How to shorten a multi dimensional array in php

I have a array that looks like this

Array
(
    [11] => Array
        (
            [1] => Array
                (
                    [type] => OPT 
                    [panel] => 1
                    [loop] => 1
                    [number] => 1
                    [zone] =>  1  
                    [value] => 38  
                )

        )

    [12] => Array
        (
            [1] => Array
                (
                    [type] => OPT 
                    [panel] => 1
                    [loop] => 2
                    [number] => 1
                    [zone] => 19  
                    [value] => 40  
                )

        )

)

I want to delete the first dimension so that it looks like this

Array
(
    [0] => Array
         (
                [type] => OPT 
                [panel] => 1
                [loop] => 1
                [number] => 1
                [zone] =>  1  
                [value] => 38  
         )

    [1] => Array
        (
                [type] => OPT 
                [panel] => 1
                [loop] => 2
                [number] => 1
                [zone] => 19  
                [value] => 40  
        )

)    

How do I do that? Sorry but I have to put in some test or the compiler won't let me post the code.

Answers


You can simply use call_user_func_array as

$result = call_user_func_array('array_merge',$your_array);

Demo


$short = array();

foreach($long as $k=>$v) {
  $short[] = $array[$k][0];
}

var_dump($short);

provided that you have only one element in 2nd level


This should work for you:

Just go through each sub array and array_merge() the arrays with your $result together, e.g.

<?php

    $result = [];

    foreach($arr as $v)
        $result = array_merge($result, $v);

    print_r($result);

?>

Demo


Need Your Help

javascript jquery help

javascript jquery scroller

I am trying to find a good vertical text scroller. Basically what I want is a scroller that goes vertically but is continuous (meaning the area is never empty while waiting for the text). I can use