I have an array of arrays.
For example:
$array[] = array("1", "2", "3");
$array[] = array("5", "9", "ok");
$array[] = array("test", "ok", 8");
What is the easiest way of flattening/merging this to just one array?
Result should be:
$array = array("1", "2", "3", "5", "9", "ok", "test", "ok", "8");
Is there an easier/simpler way to get this result than doing the below?
$result = array();
foreach ($array as $subarray) {
foreach ($subarray as $value) {
array_push($result, $value);
}
}
Since PHP 5.6 you may use
...operator to provide arguments:Old answer
As suggested, you may use
array_mergefor this. If you don’t know how many values in your$arrayyou may use something like this: