php中为什么多个foreach循环中获取不到上一个foreach循环的key值
展开全部
能获取到的,应该是你的代码写错了,或者命名不规范:
<?php
$variable = array('0' => array('a' =>array('x' => array('0' => 4,'1'=>5 ),'y' =>array('0' => 1,'1'=>3 )) ,'b' =>array('s' => 7,'g' =>9)),'1'=>array('a' =>array('x' => array('0' => 8,'1'=>6 ),'y' =>array('0' => 4,'1'=>4 )) ,'b' =>array('s' => 10,'g' =>11)) );
foreach ($variable as $key => $value) {
foreach ($value as $k => $v) {
foreach ($v as $ke => $va) {
echo $key;
echo $k;
echo $ke;
exit;
}
}
}
这个都是可以输出对应的键的,不知道是我理解错误?
<?php
$variable = array('0' => array('a' =>array('x' => array('0' => 4,'1'=>5 ),'y' =>array('0' => 1,'1'=>3 )) ,'b' =>array('s' => 7,'g' =>9)),'1'=>array('a' =>array('x' => array('0' => 8,'1'=>6 ),'y' =>array('0' => 4,'1'=>4 )) ,'b' =>array('s' => 10,'g' =>11)) );
foreach ($variable as $key => $value) {
foreach ($value as $k => $v) {
foreach ($v as $ke => $va) {
echo $key;
echo $k;
echo $ke;
exit;
}
}
}
这个都是可以输出对应的键的,不知道是我理解错误?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询