Problems with PHP array

0

Dear. A MySQL query from form generates the following php array:

Array ( 
        [0] => Array ( 
                [nomtag] => Flujometro Entrada PG TK 
                [Fecha] => 2016-01-01 
                [Valor] => 1234567 
                [medida] => m3 
        ) 
        [1] => Array ( 
                [nomtag] => Flujometro Entrada PG TK 
                [Fecha] => 2016-01-02 
                [Valor] => 2223124 
                [medida] => m3 
        ) 
) 

Array ( 
        [0] => Array ( 
                [nomtag] => Entrada Recolectora PG TK 
                [Fecha] => 2016-01-01 
                [Valor] => 9876544 
                [medida] => m3 
        ) 
        [1] => Array ( 
                [nomtag] => Entrada Recolectora PG TK 
                [Fecha] => 2016-01-02 
                [Valor] => 9988112
                [medida] => m3 
        ) 
)

The result of the array is two array. I want only one consecutive array 0 1 2 3 and not two arrays 0 1 and 0 1, in the following way:

Array ( 
        [0] => Array ( 
                [nomtag] => Flujometro Entrada PG TK 
                [Fecha] => 2016-01-01 
                [Valor] => 1234567 
                [medida] => m3 
        ) 
        [1] => Array ( 
                [nomtag] => Flujometro Entrada PG TK 
                [Fecha] => 2016-01-02 
                [Valor] => 2223124 
                [medida] => m3
        )  
        [2] => Array ( 
                [nomtag] => Entrada Recolectora PG TK 
                [Fecha] => 2016-01-01 
                [Valor] => 9876544 
                [medida] => m3 
        ) 
        [3] => Array ( 
                [nomtag] => Entrada Recolectora PG TK 
                [Fecha] => 2016-01-02 
                [Valor] => 9988112 
                [medida] => m3 
        ) 
)

Is it possible to generate the latter from PHP based on the first one? Greetings and thanks in advance.

    
asked by Carlos Cataldo 13.01.2017 в 18:14
source

1 answer

2
  • To join 2 (or more) array you can use array_merge :

    $resultado = array_merge($array1, $array2);
    

    Applied to your case you should do it like this:

    $resultado = array_merge($array[0], $array[1]);
    

    Demo

  • You can also use call_user_func_array combined with array_merge for " flatten "the input array.

    $resultado = call_user_func_array('array_merge',$array);
    

    Demo

answered by 13.01.2017 / 18:38
source