Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5980645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:49:50+00:00 2026-05-22T21:49:50+00:00

I made this object array $trailheads[] = new StdClass; Then I was putting an

  • 0

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>';
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:49:51+00:00Added an answer on May 22, 2026 at 9:49 pm

    After this:

    $trailheads[] = new StdClass;
    

    your $trailheads array contains on element, an instance of StdClass.

    Then you add more elements, but there will be that first one.

    Maybe you wanted to initialize the $trailheads[] like that, but instead you gave value to one of the array elements. Use this instead:

    $trailheads = array();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is getting made in a static void method in the main class. (class
I made a custom object that inherits from NSObject. Let's say I have an
I have a bug in my code that made me think I don't fully
I had a hard time trying to word my question properly, so i'm sorry
Just today I noticed a strange behavior in an object model that was previously
I just started doing jQuery last week, and so far I already made some
Alright, so I'm trying to write a bunch of Sudoku puzzles to a file.
I had a navigation application that was working normally. In the table view, the
i've hooked up logging in my application to automatically log changes to certain entities
I've been profiling my webapp locally on my pc with VisualVM. I'm pretty certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.