2012-04-02 403 views
2

我與Magento的API調用和交互後:遍歷多維數組

$result = $soap->call($session_id, 'catalog_product.list'); 

我得到一個數組,充滿了與他們的內部信息數組的,我是因爲執行print_f後知道這它,我得到以下結果:

Array([0] => Array([product_id] => 2 [sku] => 401HCS [name] => Paul Penders Hydrating Control Serum (20g) [set] => 4 [type] => simple [category_ids] => 

Array ([0] => 4 [1] => 15 [2] => 43)) 

[1] => Array ([product_id] => 3 [sku] => 400ICT [name] => Paul Penders Intensive Clarifying Therapy (ICT) [set] => 4 [type] => simple [category_ids] 

Array ([0] => 4 [1] => 11 [2] => 43)) 

[2] => Array ([product_id] => 4 [sku] => 402CFE [name] => Paul Penders Herbal Citrus Fruit Exfoliant (60ml) [set] => 4 [type] => simple [category_ids] => 

它沒有明顯的縮進,我這樣做,爲方便閱讀,所以我的問題是,我將如何去約穿越某種循環,以進入每一個陣列,並得到[product_id]和其他元素?提前致謝!

+0

你的問題與android有什麼關係? – Blackbelt 2012-04-02 17:21:36

+0

與android無關。也許刪除標籤? – erbsman 2012-04-02 17:23:57

+0

哎呀,最近一直在做很多android,我的錯誤。 – 2012-04-02 18:05:09

回答

5

它被標記爲「java」,但很明顯是php。你可以像這樣遍歷它:

foreach ($result as $id => $data) { 
    foreach ($data as $key => $value) { 
     switch ($key) { 
     case 'product_id': 
      // do things 
      break; 
     case 'sku': 
      // do things 
      break; 
     // (...) 
+0

謝謝,作品完美無瑕! – 2012-04-02 18:44:14