Transform 2 php array into a single array

1

I have 2 Arrays :

"val" => {
    "0": "2"
    "1": "4"
    "2": "6"
    "3": null
    "4": null
}

"p" => {
    "0": "4"
    "1": "5"
    "2": "7"
    "3": "8"
    "4": "9"
}

So I want to get the elements of array val which are 2 4 6 and add in the same 4 5 7.

All in a single array .

    
asked by anonymous 08.11.2018 / 18:04

1 answer

3

Good afternoon, let's get started: you can first use Array_merge to join the 2 arrays , taking the example you gave you have the 2 arrays:

$val = [
    "0" => "2",
    "1" => "4",
    "2" => "6",
    "3" => null,
    "4" => null
];

$p = [
    "0" => "4",
    "1" => "5",
    "2" => "7",
    "3" => "8",
    "4" => "9"
];

Example:

$array_mergido = array_merge($val, $p);

But if you only want unique values without being repeated you can use Array_unique : / p>

$array_mergido = array_unique(array_merge($val, $p));
    
08.11.2018 / 18:21