How to merge multiple arrays from a single array variable ? lets say i have this in one array variable
Those are in one variable .. $array = array(array(1), array(2));
Array
(
[0] => 1
)
Array
(
[0] => 2
)
how to end up with this
Array
(
[0] => 1
[1] => 2
)
This is the PHP equivalent of javascript Function#apply
(generate an argument list from an array):
$result = call_user_func_array("array_merge", $input);
demo: http://3v4l.org/nKfjp
This may work:
$array1 = array("item1" => "orange", "item2" => "apple", "item3" => "grape");
$array2 = array("key1" => "peach", "key2" => "apple", "key3" => "plumb");
$array3 = array("val1" => "lemon");
$newArray = array_merge($array1, $array2, $array3);
foreach ($newArray as $key => $value) {
echo "$key - <strong>$value</strong> <br />";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With