foreach得到子阵

时间:2012-07-26 09:59:44

标签: php mongodb foreach

我遇到以下代码的问题。

if ($cursor->count() > 0)
        {
            $test = array();
            // iterate through the results
            while( $cursor->hasNext() ) {   
            $test[] = ($cursor->getNext());
            }
            //print_r($test);
            foreach($test as $d) {
                print_r($d);    
                $current_name = $d[0]['personal']['name'];
           }
        }

但是当我在我的mongodb中时,我有

array("personal"=>array("name"=>"rusty"));

1 个答案:

答案 0 :(得分:1)

修改为:

 foreach($test as $d) 
 {
            print_r($d);    
            $current_name = $d['personal']['name'];
 }