如何遍历如下结构:
$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
)
);
假设你想要转弯…
foreach($this->user[$userid]['userturn'] as $k=>$turn){
print_r($turn);
}
你可以使用简单的递归:
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]);