0

I have an array look like this. I would like to make current value (if not last in array) as a key and loop through array.

$_array = array(
  [0] => Array
    (
        [0] => first
        [1] => title
        [2] => Harry Potter
    )

  [1] => Array
    (
        [0] => first
        [1] => content
        [2] => title
        [3] => Chapter One
    )
 [2] => Array
    (
        [0] => first
        [1] => content
        [2] => paragraph
        [3] => Hello...
    )
  [3] => Array
    (
        [0] => second
        [1] => title
        [2] => The Lord of the Rings
    )
);

new array will look like this

array('first' => array(
        'title'=>'Harry Potter',
        'content' => array(
           'title' => 'Chapter One',
           'paragraph' => 'Hello...'
        ),
      'second' => array(
          'title' => 'The Lord of the Rings'
       )
);

this is easy to do this, but I want to make it dynamic.

$_new = ($array[0] => array($array[1] => $array[2] ...);

ps. sorry for my english.

0 Answers0