0

I have an array like following.It is combination of both numeric key and associate key.

[0] => Array
    (
        [test] => Array
            (
                [a] => lorem
                [id] => 2
            )

        [0] => Array
            (
                [b] => 2
            )
     )

Desired Array

[0] => Array
    (
        [0] => Array
            (
                [a] => lorem
                [id] => 2
                [b] => 2
            )
   )

How can i convert this array into numeric array like following(best way). Although I have convert this array in desired array with use of foreach. Used method -

for($i=0;isset($array[$i]);$i++){
                        $temp[$i]=$array[$i]['test'];
                        $temp[$i]['b']=$array[$i][0]['b'];
                    }
mjdevloper
  • 1,553
  • 8
  • 33
  • 69
  • 1
    What did you try so far? – Max Oct 13 '14 at 08:43
  • Can you add you code here? – Rajesh Ujade Oct 13 '14 at 08:44
  • How specifically does the array look like the one you posted? Is it always structured like this, or could it have more fields? What do you want to do with key-overlap? Or deeper nested arrays? – Erik Oct 13 '14 at 08:49
  • Rohit, maybe it's best to have a look at the basic ways of traversing a PHP array ([`foreach`](http://php.net/manual/en/control-structures.foreach.php) construct) and the basic PHP [array functions](http://nl1.php.net/manual/en/ref.array.php). – Max Oct 13 '14 at 08:51

0 Answers0