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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:49:11+00:00 2026-05-27T09:49:11+00:00

I have an array that I declare like this: $health_array = array( ); For

  • 0

I have an array that I declare like this:

$health_array = array( );

For every iteration I try to put these 3 items in it like this:

$health_array["num_problems"] = $num_problems;
$health_array["category_id"] = $category_id;
$health_array["category_name"] = $category_name;

But when I loop through the array I get gibberish. Here is how I loop through it:

foreach ($health_array as $i => $row)
{
    echo  '<p>'.$row['category_name'].' '.$row['category_id'].' '.$row['num_problems'].'</p>';
} 

Any idea what I am doing wrong?

Thanks!!

  • 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-27T09:49:12+00:00Added an answer on May 27, 2026 at 9:49 am

    Your problem comes from the fact that you want to do a multi-dimensional array and you’re creating a monodimensional one, by overwriting each time the same 3 elements.

    You should do something like:

    $health_array = array();
    $tmp = array();
    
    $tmp["num_problems"] = 5;
    $tmp["category_id"] = 8;
    $tmp["category_name"] = "something";
    $health_array[] = $tmp;
    
    $tmp["num_problems"] = 15;
    $tmp["category_id"] = 22;
    $tmp["category_name"] = "something else";
    $health_array[] = $tmp;
    
    foreach ($health_array as $h)
        {
        echo $h["num_problems"]." - ".$h["category_id"]." - ".$h["category_name"]."<br />";
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a array that looks like this Array ( [provider] => Array (
I have an array that looks like this: Array ( [0] => Array (
I have a try-catch block that iterates over a set of records like this:
I have an array that looks like: $fields = array( f1 => array(test), f2
I have an array that looks like $numbers = array('first', 'second', 'third'); I want
What's the right way to do this? I have an array that I will
I have to work with multiple SQL Server tables that generally look like this:
So I have a bunch of boolean arrays that I would like to put
I have a multidimensional array that is behaving unexpectedly and I would like to
I have this code, that takes a string and splits it into an array:

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.