$newarray 中有一个数组,如下所示
Array
(
[111] => Array
(
[123] => 0
[124] => 0
[125] => 0
[126] => 0
[127] => 0
[128] => 0
[129] => 0
[130] => 1
[131] => 1
[132] => 1
[133] => 1
[134] => 1
[135] => 1
)
[222] => Array
(
[123] => 0
[124] => 0
[125] => 0
[126] => 1
[127] => 1
[128] => 1
[129] => 1
[130] => 1
[131] => 1
[132] => 1
[133] => 1
[134] => 1
[135] => 1
)
[333] => Array
(
[256] => 0
[321] => 0
[456] => 0
[489] => 0
[652] => 1
[741] => 1
[965] => 0
)
)
我需要在foreach中获取密钥名称(在本例中为111222和333):
不管我做什么,下面的人总是吐出"222"3次。有什么明显的吗?
foreach($newarray as $value) {
echo key($newarray) . "<br />";
}
输出
222
222
222
试试这个:
foreach($newarray as $key => $value)
{
echo $key . "<br />";
}
这是使用foreach 的正确方法
foreach($newarray as $key=>$value) {
echo $key . "<br />";
}
或者你可以使用
print_r(array_keys($newarray));