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 8468203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:51:58+00:00 2026-06-10T15:51:58+00:00

I will be honest, I have just started learning objects and I am stuck.

  • 0

I will be honest, I have just started learning objects and I am stuck.

I want to loop through an array of objects and display the name and description for each. But either nothing is displayed or it displays all the names first and then all the descriptions.

I am pulling the information from an API into the object:

// get tasks
foreach($tasksList->items  as $task_details) {
    $tasks_name[$task_details->id]=$task_details->name;
    $tasks_desc[$task_details->id]=$task_details->description;
    $tasks_details[$task_details->id]=$task_details->id;
    $tasks_progress[$task_details->id]=$task_details->progress;
}

foreach($tasks_name as $taskid=>$my_task_name) {
    echo "Task_Name: " . $my_task_name . "</br>";
    $task_id = $task_details->id;

    foreach($tasks_desc as $taskid1=>$my_task_desc) {
        if($taskid==$task_details->id) {
            echo "Task_Desc: " . $my_task_desc . "</br>";   
        }
    }   
}

Now what I don’t understand is: inside the first foreach loop it is like a while loop while i=0, it checks $tasks_name[0], then $tasks_name[1] and so on.

However, I am not sure how to figure out what the id is in the current loop it is on, so I can tell it to only print the description of the current loop and not display all of them.

To be honest I am copying this from another example, but I don’t quite understand it. I plan to study objects more, but this is holding me up on my current code:

foreach($tasks_desc as $taskid1=>$my_task_desc)

I understand it is looping through all the $tasks_desc and assigning the value to $my_task_desc but what is the signifigance of $taskid?

Sorry for the newbie questions. 🙂

  • 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-06-10T15:51:59+00:00Added an answer on June 10, 2026 at 3:51 pm

    This is poorly written. I would move on to another tutorial if it’s a tutorial. Either that or the line that task_id is used was left out.

    Anyway, tasks_name is an array of tasks indexed by the ID. So the outer loop in the second block loops over the keys/values of that array (the ID is the key, taskid. It was assigned by $task_details->id in the first loop above).

    The second loop goes over all of the tasks again, but this time by description task_desc instead of by name. It’s trying to find the task_desc with an ID that matches the ID of the task_name before (which would make it the same task).

    That’s unnecessary, though, because you could just store all of the entries (name, desc, etc.) in one array indexed by the ID instead of storing each in their own array:

    (this is the first loop):

    foreach($tasksList->items  as $task_details) {
       $all_tasks[$task_details->id]['name'] = $task_details->name;
       $all_tasks[$task_details->id]['desc'] =$task_details->description;
       // Don't need the ID again; it's the key
       $all_tasks[$task_details->id]['progress'] = $task_details->progress;
    }
    

    However, you don’t even need to do that, because you can just iterate over tasksList->items when you need to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to develop a gesture recognition. I'm considering using the Kinect to have
Right i am just getting into OpenGL ES, and if i am honest it
To be honest, I actually have a solution for this, but Google search finds
I am trying to nicely display fractions in my iPhone application. Previously I have
I will be honest here - I am pretty sure I am not approaching
I have a bit of a dilemma, which to be honest is a fringe
I was just browsing through questions on stack overflow, and i've come up to
I have an array of integers, which could run into the hundreds of thousands
I have an array that is of size 4,9,16 or 25 (according to the
Will the following code cause a ConcurrentModificationException or other side effects? ArrayList<String> newList =

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.