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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:23:55+00:00 2026-06-06T22:23:55+00:00

I am trying to construct a deeply nested associative array but i don’t know

  • 0

I am trying to construct a deeply nested associative array but i don’t know what the rules are in constructing one.I have this theoritical array:

-one
-two
-three
-four
    -one
    -two
    -three
    -four
-five
-six
-seven
-eight
-nine
    -one
    -two            
    -three 
            -one
            -two
            -three
            -four
            -five
            -six

and i made this attempt at representing that as a php associative array;

$associative = array(
'one' => 'one-1',
'two' => 'two-2',
'three' => 'three-3',
'four' => 'four-4'
(
    'one' => 'one-four-1',
    'two' => 'two-four-2',
    'three' => 'three-four-3',
    'four' => 'four-four-4'
)
'five' => 'five-5',
'six' => 'six-6',
'seven' => 'seven-7',
'eight' => 'eight-8',
'nine' => 'nine-9'
(
    'one' => 'one-nine-1',
    'two' => 'two-nine-2',          
    'three' => 'three-nine-3' 
(   
        'one' => 'one-nine-three-1',
        'two' => 'two-nine-three-2',
        'three' => 'three-nine-three-3',
        'four' => 'four-nine-three-4',
        'five' => 'five-nine-three-5',
        'six' => 'six-nine-three-6'
))
);
$keys = array_values($associative);
echo $keys[0];

When i try executing the php snippet i get this error;

Parse error: syntax error, unexpected ‘(‘, expecting ‘)’ in
C:\wamp\www\array.php on line 7

So my question is,what is the correct way of writing such an array and what rule should i follow when i wish to add more children?.

Note:In my theoritical array,four has four children,nine has three children and three has six children.Anyway,i hope the idea of having children is understood in my dummy array.

  • 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-06T22:23:57+00:00Added an answer on June 6, 2026 at 10:23 pm

    The subarrays are actual values of your top-level array elements, and you have to initiate them using array() as well:

    $associative = array(
        'one' => 'one-1',
        'two' => 'two-2',
        'three' => 'three-3',
        'four' => array(
            'one' => 'one-four-1',
            'two' => 'two-four-2',
            'three' => 'three-four-3',
            'four' => 'four-four-4'
        ),
        'five' => 'five-5',
        'six' => 'six-6',
        'seven' => 'seven-7',
        'eight' => 'eight-8',
        'nine' => array(
            'one' => 'one-nine-1',
            'two' => 'two-nine-2',          
            'three' => array(   
                'one' => 'one-nine-three-1',
                'two' => 'two-nine-three-2',
                'three' => 'three-nine-three-3',
                'four' => 'four-nine-three-4',
                'five' => 'five-nine-three-5',
                'six' => 'six-nine-three-6'
            ),
        ),
    );
    

    Note that I also added ,s after each closing ), because, like I said, the arrays are values of the parent array elements.

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

Sidebar

Related Questions

I'm trying to construct a 2D array in the form of pointers-to-pointers. This doesn't
I am trying to construct a customized map in raphaeljs , in this i
I am trying to construct a Groovy statement to find values that don't exist
I'm trying construct a PostgreSQL query that does the following but so far my
I'm trying to construct nested maps in Scala, where both the outer and inner
I have been trying to construct a checkbox node tree . My specification is
I've been trying to construct a ruby regex which matches trailing spaces - but
Trying to construct a helper class that will return an arraylist, but I'm getting
I am trying to construct a DateTime in C# one step at a time,
I'm trying to construct a Link. The resulting Link should look something like this:

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.