0

My Array

Array ( 
    [0] => stdClass Object ( 
        [name] => name
        [title] => -- 
        [description] => No
        [url] => http://google.com
        [updated] => 1553419890 ) 
    [1] => stdClass Object ( 
        [name] => Hey
        [title] => Title
        [description] => Yes
        [url] =>  http://twitter.com
        [updated] => 1553321131 ) 
)

How do I loop the above array with for each?

dbrumann
  • 16,803
  • 2
  • 42
  • 58
frankosa
  • 15
  • 6

2 Answers2

0

//for an array in array

foreach(name_of_your_array as array) { data = array["name"]; }

//for an object in your array

foreach(name_of_your_array as array) { data = array->name; } an example of how you can do

0

I think you are looking for how to loop through the array using key-value pair format

foreach($name_of_your_records_array As $key => $ object)
{
    $count_of_record = $key;
    $name = $object->name;
    $title = $object->title;
    //...
}

Reference link :

PHP manual foreach

Accessing object inside an array PHP

LEE Hau Chon
  • 435
  • 3
  • 12