douying8666
2012-07-02 23:43
浏览 330
已采纳

如何从php中的多维数组中获取所有特定键值?

How can I get the all the 'name' and 'city' value back in an array from the following multidimensional array?

$myarray=Array(Array('name' => 'A','id' => '1', 'phone' => '416-23-55',
Base => Array ('city'  => 'toronto'),'EBase' => Array('city' => 'North York'),
'Qty' => '1'),  (Array('name' =>'B','id' => '1','phone' => '416-53-66','Base' => 
Array  ('city' => 'qing'), 'EBase' => Array('city' => 'chong'),'Qty' => '2')));

I expect the returned value be

$namearray=Array('A','B');
$basecityarray=Array('toronto','qing');
$Ebasecityarray=Array('North York','chong');

Thank you!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsbqfrr098575666 2012-07-03 00:00
    已采纳

    You can definitely try something like this:

    $shop = array( array( 'Title' => "rose", 
                      'Price' => 1.25,
                      'Number' => 15 
                    ),
               array( 'Title' => "daisy", 
                      'Price' => 0.75,
                      'Number' => 25,
                    ),
               array( 'Title' => "orchid", 
                      'Price' => 1.15,
                      'Number' => 7 
                    )
             );
    

    You can access the first row as

    echo $shop[0][0]." costs ".$shop[0][1]." and you get ".$shop[0][2]."<br />";
    

    or $shop[0]->Title will return to you rose.

    打赏 评论

相关推荐 更多相似问题