【问题标题】:Retrieving values from multi level array从多级数组中检索值
【发布时间】:2013-10-09 00:44:35
【问题描述】:

您好希望获得有关如何执行此操作的帮助。因为到目前为止我正在做的事情是失败的。 这是json转换为数组的示例输出。

        Array
    (
        [0] => Array
            (
                [0] => Array
                    (
                        [value] => lit-PR-00-Preparing-Precise-Polymer-Solutions.html
                    )

            )

        [1] => Array
            (
                [0] => Array
                    (
                        [value] => 90Plus
                    )

            )

        [2] => Array
            (
                [0] => Array
                    (
                        [value] => Particle Size Analyzer
                    )

            )

    )

到目前为止,这就是我到目前为止所得到的,它仍然没有输出我需要的值。感谢您对我做错的事情的帮助。

$decode = json_decode($row['elements'], true);

                echo '<pre>';
                //print_r($decode);
                print_r(array_values($decode));
                echo '</pre>';

                echo ($value['0'][1][value]);

【问题讨论】:

    标签: php arrays json multidimensional-array decode


    【解决方案1】:
    $decode = json_decode($row['elements'], true);
    
    // iterate through array
    foreach($decode as $array_row) {
      echo $array_row[0]['value'];
    }
    
    // display specific row #2
    echo $decode[2][0]['value'];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多