简体   繁体   中英

foreach loop in multidimensional array

I'm trying to output an array like so:

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

The array is multidimensional like this:

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

I've tried this:

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

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

But end up with this:

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

How can I extract the nested arrays?

it was JSON so try this, $post_fields = json_decode($post_fields, true);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM