Unifying values of an array

Asked

Viewed 67 times

0

Performing a query in the database returns these values in an array called $arrayExcluir and I need these values to be transferred to a single array (without subdivision) for me to be able to use for my purposes, this key must be with increasing value (0,1,2..).

How it is displayed in the browser:

Array
(
    [0] => Array
        (
            [0] => 48609
            [1] => 48613
        )

    [1] => Array
        (
            [0] => 50847
        )

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

    [3] => Array
        (
            [0] => 47686
        )
...

In my researches I found the array_column in the php documentation that only does not work in my code by taking a "value" of each array, not picking more than one, I would like to know a possible solution to my problem.

Using array_column provides the following fields:

array_column(array, column_key, index_key)

It is possible to do this va foreach or just with array_column?

Using this code snippet:

array_column($arrayExcluir, 0));

it returns only one value of each, but I need all that are in each array..

  • you have tried using merge arrays?

2 answers

5

What you own is something like:

$arrayExcluir = [[48609, 48613], [50847], [51709], [47686]];

Then just use the function array_merge to merge all the arrays and, to do so, simply deconstruct the array original when passing it by parameter:

$valores = array_merge(...$arrayExcluir);

It would return something like:

Array
(
    [0] => 48609
    [1] => 48613
    [2] => 50847
    [3] => 51709
    [4] => 47686
)

Three points in the parameter of a function in a class, for what purpose?

2


Do the following:

$res = call_user_func_array('array_merge',$arrayExcluir);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.