1

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;
        }
?>      
3
  • where is data in your array response? Commented May 2, 2019 at 10:27
  • What does $record contain? Why don't you iterate over $final? Commented May 2, 2019 at 10:28
  • can you share your $responsehere? Commented May 2, 2019 at 10:28

1 Answer 1

1

You can rewrite your foreach loop:

<?php

$final = json_decode($response,true);

foreach($final as $key => $re)
   {
     echo $re['_id']. "<br>";
   }
Sign up to request clarification or add additional context in comments.

1 Comment

you are basically saying array notation works - but object notation won't - where is that logic coming from ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.