Skip to main content
added 306 characters in body
Source Link
Spudley
  • 169.3k
  • 39
  • 240
  • 309

The trips and segments elements are arrays of objects, not a single object.

So you need to reference the array element [0] which part of the structure.

$trips = $routings[0]->trips;
$segments = $trips[0]->segments;

Note, that there appear to be two trips, you'll also need $trips[1]->segments if you want all the segments.

More likely, you'll be wanting to use foreach() loops to read them, rather than directly referencing the array keys.

Something like this?

foreach($routings as $routing) {
    $trips = $routing->trips;
    .... do something here with $trips? ....
    foreach($trips as $trip) {
         $segments = $trip->segments;
         .... do something here with $segments? ....
    }
}

The trips and segments elements are arrays of objects, not a single object.

So you need to reference the array element [0] which part of the structure.

$trips = $routings[0]->trips;
$segments = $trips[0]->segments;

Note, that there appear to be two trips, you'll also need $trips[1]->segments if you want all the segments.

More likely, you'll be wanting to use foreach() loops to read them, rather than directly referencing the array keys.

The trips and segments elements are arrays of objects, not a single object.

So you need to reference the array element [0] which part of the structure.

$trips = $routings[0]->trips;
$segments = $trips[0]->segments;

Note, that there appear to be two trips, you'll also need $trips[1]->segments if you want all the segments.

More likely, you'll be wanting to use foreach() loops to read them, rather than directly referencing the array keys.

Something like this?

foreach($routings as $routing) {
    $trips = $routing->trips;
    .... do something here with $trips? ....
    foreach($trips as $trip) {
         $segments = $trip->segments;
         .... do something here with $segments? ....
    }
}
Source Link
Spudley
  • 169.3k
  • 39
  • 240
  • 309

The trips and segments elements are arrays of objects, not a single object.

So you need to reference the array element [0] which part of the structure.

$trips = $routings[0]->trips;
$segments = $trips[0]->segments;

Note, that there appear to be two trips, you'll also need $trips[1]->segments if you want all the segments.

More likely, you'll be wanting to use foreach() loops to read them, rather than directly referencing the array keys.