I made this object array
$trailheads[] = new StdClass;
Then I was putting an object in there each time it looped
$trailheads[] = $trailhead;
Then I returned the whole thing from the function like this:
$ret->ok = empty($errors);
$ret->errors = $errors;
$ret->o = $trailheads;
return $ret;
Once I got the values back, and loop through the results in the trailheads[] I keep looping 3 times instead of the expected 2. Is there a reason an extra iteration might be happening?
Here is how I try to loop:
foreach ($trailhead_list->o as $key)
{
$objkey = (object) $key;
echo '<p><h3>Trailhead Name: '.$objkey->trailhead_name.'</h3></p>';
}