2012-07-02 131 views
0

如何從下列多維數組中獲取數組中所有「名稱」和「城市」值?如何從PHP中的多維數組中獲取所有特定的鍵值?

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

我希望返回的值是

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

謝謝!

+0

你說得對。我更新了預期的結果。你能幫忙嗎? – aje

+0

只需使用'foreach'或'array_map' – Serjio

回答

0

你絕對可以嘗試這樣的事情:

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

您可以訪問的第一行作爲

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

$shop[0]->Title會回到你rose

相關問題