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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:20:37+00:00 2026-05-30T11:20:37+00:00

I have this combination of multi-dimensional array but I can’t print the correct value

  • 0

I have this combination of multi-dimensional array but I can’t print the correct value out on the screen,

$parent = array(
    array(
        'function_name' => 'home',
        'screen_name' => 'Home'
        ),

    array(
        'function_name' => 'categories',
        'screen_name' => 'Categories',


        array(
            'function_name' => 'post',
            'screen_name' => 'Post',
            )
        ),

    array(
        'function_name' => 'pages',
        'screen_name' => 'Pages',


        array(
            'function_name' => 'add',
            'screen_name' => 'Add',

            array(
                'function_name' => 'manage',
                'screen_name' => 'Manage'
                )
            )
        )
);

some arrays are by themselves, some are with sub arrays, and some sub arrays have subsub arrays.

foreach($parent as $index => $item)
{   
    echo 'parent - '.$item['screen_name'].'<br/>';

    foreach($item as $child)
    {
        echo 'child - '.$child['screen_name'].'<br/>';

        foreach($child as $grandchild)
        {
            echo 'grandchild - '.$grandchild['screen_name'].'<br/>';
        }
    }
}

error message,

Warning: Invalid argument supplied for foreach() in -> foreach($child as $grandchild)

the result I am looking for is like this,

parent - Home
parent - Categories
  child - Post
parent - Pages
  child - Add
     grandchild - Manage

EDIT:

I tried with this test below,

foreach ($system as $inner_1) {

    if (is_array($inner_1)) 
    {

        foreach ($inner_1 as $inner_2) 
        {

             if (is_array($inner_2)) 
             {
                  foreach ($inner_2 as $inner_3) 
                  {
                     var_dump($inner_3['function_name']);
                  }
             }
        }
    }
}

but I get a strange result,

string 'p' (length=1) // don't know why I get this.
string 'P' (length=1) // don't know why I get this.

string 'a' (length=1) // don't know why I get this.
string 'A' (length=1) // don't know why I get this.

string 'manage' (length=6) // correct result.
  • 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-30T11:20:39+00:00Added an answer on May 30, 2026 at 11:20 am

    When running foreach($item as $child) on $parent[1], $child takes the following values: 'home', 'Home' and an array.

    What about keeping the arrays purely associative?

    $parent = array(
        array(
            'function_name' => 'categories',
            'screen_name' => 'Categories',
            'children' => array(
                array(
                    'function_name' => 'post',
                    'screen_name' => 'Post'
                ),
                array(
                    'function_name' => 'review',
                    'screen_name' => 'Review',
                    'children' => array(
                        ...
                    )
                ),
            )
        )
    );
    

    This way you can run foreach ($item['children'] as $child) knowing the argument is an array (you need to make sure that $item['children'] exists and is an array).

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

Sidebar

Related Questions

I imagine this is simple - but I can't find the right combination of
I have a very specific problem here. I have a multi-dimensional array that I
I have implemented this code, but fail at compilation (VC2008 Express Ed.) : Now
I have this setup where in my development copy I can commit changes on
I have posted this to ServerFault, but the Node.js community seems tiny there, so
I have this function that creates a unique number for hard-disk and CPU combination.
I am trying to figure out how this DropDownListFor works but with no success.
I have this homework that I gotta finish, but then something about it is
I have a multi-module project, and I am using profiles in the parent pom
so i have this problem.. POLL followed by a combination of 10 As, Ds,

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.