php 多维数组中的foreach循环

cclgggtu  于 2022-12-02  发布在  PHP
关注(0)|答案(1)|浏览(169)

我尝试输出一个数组,如下所示:

durations":[{"months":"36"},{"months":"48"}],"duration_default":"60","insurance_factor":"0","lease_factor":"0.4637","create_fee":"2500

数组是多维的,如下所示:

Array ( [durations] => Array ( [0] => Array ( [months] => 36 ) [1] => Array ( [months] => 48 ) ) [duration_default] => 60 [insurance_factor] => 0 [lease_factor] => 44 [create_fee] => 2500 ) )

我试过这个:

foreach ($post_fields as $key=>$item){

    echo ""$key" : "$item", ";
  
}

但最后还是这样:

data-calc="{"durations" : "Array", "duration_default" : "60", "insurance_factor" : "0.9909", "lease_factor" : "44", "create_fee" : "2500", "frequency" : "month", "min_price" : "2222", "margins" : "Array",

如何提取嵌套数组?

5ktev3wc

5ktev3wc1#

它是JSON,所以尝试以下代码:$post_fields = json_decode($post_fields , true);

foreach($post_fields as $key=>$item){
   echo $item;}

相关问题