我怎样才能遍历如下的结构:
$this->user[$userid] = array(
"initial" => array(
"amount" =>$amount,
"cards" =>$cards
),
"userturn" => array(
"userturn1" => array(
"action"=>$action,
"amount"=>$amount,
"date"=>$datetime
),
"userturn2" => array(
"action"=>$action,
"amount"=>$amount,
"date"=>$datetime
),
.
.
.
.
n times
)
);
答案 0 :(得分:1)
假设你想转弯..
foreach($this->user[$userid]['userturn'] as $k=>$turn){
print_r($turn);
}
答案 1 :(得分:0)
你可以使用简单的递归:
function recurseLoop($arr){
foreach($arr as $key=>$value){
echo('key:' . $key);
if(gettype($value) == 'array'){
recurseLoop($value);
}
else{
echo('value:' . $value);
}
}
}
recurseLoop($this->user[$userid]);