IF you have an array within an array, how can you remove the outer array:
$outer_array = array(0 => array(
'key1' => 'value1',
'key2' => 'value2'
));
print_r($outer_array) produces:
Array
(
[0] => Array
(
[key1] => value1
[key2] => value2
)
)
Is there a function built into php so you are left with:
Array
(
[key1] => value1
[key2] => value2
)
You can simply do:
$new_array = $outer_array[0];
print_r($new_array);
Result:
Array
(
[key1] => value1
[key2] => value2
)
Note: As pointed out by @netcoder, to make it work for both numeric and string indexes, you can do:
$new_array = $outer_array[0];
$new_array = reset($out_arr);
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