So i maybe have a simple question. but i just can't figure out how to solve this. I got 1 array that looks like this.
Array
(
[0] => Array
(
[0] => 1
[1] => 2
)
[1] => Array
(
[0] => 3
)
)
1
is it possible to merge the two keys into 1 key. and merge it into like this.
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[3] => 3
)
)
1
much thanks
You can user php array_merge function like this:
$final_array = array();
foreach ($your_array as $a){
$final_array = array_merge($final_array,$a);
}
echo '<pre>';
print_r($final_array);
die;
Solution for unknown number of subarrays is:
$ar = array(array(1,3), array(2,4), array(5));
$r = call_user_func_array('array_merge', $ar);
print_r($r);
$array = Array
(
'0' => Array
(
'0' => 1,
'1' => 2
),
'1' => Array
(
'0' => 3
)
);
$result = array();
foreach($array as $_array)
{
foreach($_array as $__array)
{
$result[] = $__array;
}
}
print_r($result);