繁体   English   中英

我需要 PHP 阵列的帮助

[英]I need help in PHP array

我的数组是 -

Array
(
    [0] => accordion
    [1] => bars
 
)

我需要以一种简单的方式访问这个数组。 可以喜欢下面的系统吗?

if(isset($array['accordion'])){
// do something...
}

您可以使用键访问数组元素。

php 中的数组可能如下所示:

$my_array = ["foo", "bar"];

// These values of this array are accessed using the key - the numeric index of the key, where 0 is the first item in the array.

$my_array[0]; // points to the value "foo"
$my_array[1]; // points to the value "bar"

或者您可以使用命名键访问数组的值。 像这样:

$my_array = [
   "name" => "John",
   "lastname" => "Doe"
];

// Then you approach the values of this array as follows:
$my_array['name'];  // points to the value "John"
$my_array['lastname']; // points to the value "Doe"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM