Removing an outer array:
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 funct开发者_JAVA技巧ion 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);
You can simple do :
print_r(array_shift($outer_array))
Hope this will work
精彩评论