dongshi1606 2012-04-02 17:15
浏览 36
已采纳

遍历多维数组

I'm interacting with the Magento API and after calling:

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

I get an array, full of arrays with information inside of them, I know this because after performing print_f on it I get the following result:

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] => 

It is not indented obviously, i did that for easy reading, so my question is how would I go about traversing some kind of loop in order to go into every array and get the [product_id] and the other elements? Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongpao1918 2012-04-02 17:25
    关注

    It's tagged 'java' but it clearly is php. You can traverse it like this:

    foreach ($result as $id => $data) {
       foreach ($data as $key => $value) {
          switch ($key) {
             case 'product_id':
                // do things
                break;
             case 'sku':
                // do things
                break;
             // (...)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?