Tag: 数组键

PHP – 获取数组值的键名

我有一个数组如下: function example() { /* some stuff here that pushes items with dynamically created key strings into an array */ return array( // now lets pretend it returns the created array 'firstStringName' => $whatEver, 'secondStringName' => $somethingElse ); } $arr = example(); // now I know that $arr contains $arr['firstStringName']; 我需要找出$arr['firstStringName']的索引,以便能够遍历array_keys($arr)并通过其索引返回键string'firstStringName' 。 我怎样才能做到这一点?

array_key_exists不起作用

array_key_exists不适用于大型multidimensional array。 例如 $arr = array( '1' => 10, '2' => array( '21' => 21, '22' => 22, '23' => array( 'test' => 100, '231' => 231 ), ), '3' => 30, '4' => 40 ); array_key_exists('test',$ arr)返回'false',但它可以处理一些简单的数组。

在PHP中使用array 可以吗?

可以使用没有单引号或双引号的数组像$ array [key]? 我认为这是不好的,因为如果我不使用单引号或双引号,PHP首先查找常量。 我的一位同事告诉我说没关系。 你们有什么感想?