0

我如何遍历如下结构:

    $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
                                                     )                                                                

                         );  
4

2 回答 2

1

假设你想转弯..

foreach($this->user[$userid]['userturn'] as $k=>$turn){
    print_r($turn);
}
于 2013-04-16T12:09:40.437 回答
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]);
于 2013-04-16T12:06:03.180 回答