-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,116
  • 5
  • 38
  • 78
Edvard Åkerberg
  • 2,041
  • 1
  • 24
  • 42

2 Answers2

3

Use as array and go one level more

foreach ($positions['data'] as $position) {
 echo $position['title'];
}
Maninderpreet Singh
  • 2,509
  • 2
  • 16
  • 30
2

This should work:

foreach ($positions['data'] as $position) {
     echo $position['title'];
}
James
  • 5,116
  • 5
  • 38
  • 78
Alexey Mezenin
  • 148,626
  • 22
  • 267
  • 261