-1

Hi I am going to make tree array for multilevel category menu and I have found the solution from below link:

stackoverflow answer

But my problem is that i am getting output of my array as FORMAT-1 and in the above given link the source array required as FORMAT-2

So can you please give me a hand for how to convert my array from FORMAT-1 to FORMAT-2

FORMAT-1

Array
(
    [0] => Array
        (
            [category_id] => 11
            [category_name] => Accessories
            [parent_category_id] => 1
        )

    [1] => Array
        (
            [category_id] => 12
            [category_name] => Keyrings
            [parent_category_id] => 1
        )

    [2] => Array
        (
            [category_id] => 13
            [category_name] => Photo Frames/Photo Albums
            [parent_category_id] => 1
        )

)  

FORMAT-2 (I want output as below)

Array(
        Array(
                'category_id' => 11
                'category_name' => 'Accessories'
                'parent_category_id' => 1
            ),

        Array(
                'category_id' => 12
                'category_name' => 'Keyrings'
                'parent_category_id' => 1
            ),

        Array(
                'category_id' => 13
                'category_name' => 'Photo Frames/Photo Albums'
                'parent_category_id' => 1
            )

    );  

Thanks in advance for your help and much appreciated

4
  • What is wrong with array 1? Commented Mar 8, 2014 at 8:59
  • These are slightly different representations of a same array. Nothing is wrong here. Commented Mar 8, 2014 at 9:00
  • Can you explain more? What is really your problem because those two FORMATS are the same. Commented Mar 8, 2014 at 9:00
  • Please check the stackoverflow answer link in that solution function "buildTree" required array parameter as in format-2. is there any alternative for that? Commented Mar 8, 2014 at 9:02

2 Answers 2

1

Both arrays are more are like same..

Format-1 looks print_r($yourarray); version

Format-2 looks like var_export($yourarray); version.

You need to have a look at the debugger functions.. print_r(), var_dump() and var_export().

Sign up to request clarification or add additional context in comments.

1 Comment

i did it but you can check the stackoverflow answer link then you can find that the function "buildTree" required array parameter as in format-2. is there any alternative for that?
0

If your purpose is debugging you may use <pre>var_dump()</pre>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.