-1

For some reason i can't loop through this array with PHP. I want too loops through and echo title.

This is the array

Array (
[data] => Array
    (
        [0] => Array
            (
                [id] => 1
                [company_id] => 1
                [title] => Software Developer
            )

        [1] => Array
            (
                [id] => 2
                [company_id] => 2
                [title] => Accountant
            )

        [2] => Array
            (
                [id] => 3
                [company_id] => 3
                [title] => Insurance salesman
            )

    )

)

This is my code

    foreach ($positions as $position) {
     echo $position->title;
}
James
  • 5,137
  • 5
  • 40
  • 80
Edvard Åkerberg
  • 2,181
  • 1
  • 26
  • 47

2 Answers2

3

Use as array and go one level more

foreach ($positions['data'] as $position) {
 echo $position['title'];
}
Maninderpreet Singh
  • 2,569
  • 2
  • 17
  • 31
2

This should work:

foreach ($positions['data'] as $position) {
     echo $position['title'];
}
James
  • 5,137
  • 5
  • 40
  • 80
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279