简体   繁体   中英

foreach loop not working correctly with json encode Php

I have multiple array (object inside array),But whnever i run foreach loop,its working one time only,What is the problem ? where i am wrong ?

Array
(
    [0] => stdClass Object
        (
            [_id] => 5cc6896028497b75f44cbf31
        }
    [1] => stdClass Object
        (
            [_id] => 5cc6896028497b75f44cbf32
        }
    ... 
}       

Here is my code,But loop is working only time but i have many records(more than 100)

<?php
$final = json_decode($response);
$record=$final->data;
foreach($record as $re)
        {
            echo $re->_id;
        }
?>      

You can rewrite your foreach loop:

<?php

$final = json_decode($response,true);

foreach($final as $key => $re)
   {
     echo $re['_id']. "<br>";
   }

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