$one=array(
‘status’=>’ok’,
‘deptlist’=>array(
array(
‘name’=>’wangwu’,
‘age’=>’20’
),
array(
‘name’=>’lisi’,
‘age’=>’30’
),
array(
‘name’=>’cora’,
‘age’=>’21’
)
),
‘error’=>’0’
);
这个$one数组怎么遍历出 deptlist下面的name,age全部值呢
我用foreache不知道怎么遍历,通常遍历的数组都是一样的,但是这个是数组里面又有数组,不知道怎么办了
一个数组,三个值,然后其中一个值里面又有数组.
回复讨论(解决方案)
foreach($one[‘deptlist’] as $v){
echo $v[‘name’].’ ‘.$v[‘age’].”;
}
$one=array(
‘status’=>’ok’,
‘deptlist’=>array(
array(
‘name’=>’wangwu’,
‘age’=>’20’
),
array(
‘name’=>’lisi’,
‘age’=>’30’
),
array(
‘name’=>’cora’,
‘age’=>’21’
)
),
‘error’=>’0’
);
foreach($one[‘deptlist’] as $k=>$v){
echo ‘name=’.$v[‘name’].php_eol;
echo ‘age=’.$v[‘age’].php_eol;
}
name=wangwu
age=20
name=lisi
age=30
name=cora
age=21