1

i wanted to covert array values into a multidimensional associative array. Array size can be dynamic.

Array to be converted:

Array
(
    [0] => abc
    [1] => 0
    [2] => xyz
    [3] => 0
)

Expected Output:

 Array
(
    [abc] => Array
        (
            [0] => Array
                (
                    [xyz] => Array
                        (
                            [0] => 
                        )

                )

        )

)

Tried with popping first key, but that has no luck...

2
  • 1
    Why would you want to do that? In many years I have never had the need to do something like this. Maybe the problem is in some other code you are not showing us, that requires such an output - can you show us? Commented Mar 4, 2015 at 5:56
  • Its our requirement in our application Commented Mar 4, 2015 at 6:00

1 Answer 1

4

Try this..

$tmpArr =  array('Abc', '0', 'ABC','0');
$array = array();
foreach (array_reverse($tmpArr) as $arr)
$array = array($arr => $array);
Sign up to request clarification or add additional context in comments.

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.