I have an array like the following . . .
Array
(
[code] => BILL
[assets] => Array
(
[en] => Array
(
[labels] => Array
(
[datestamp] => April 30, 2013
)
[data] => Array
(
[Equity] => 88.83000000000
[Global] => 10.84000000000
[Other] => 0.33099095766
)
)
)
)
I have run the array_map function on this array to remove the [en]
array
$en = array_map(function ($e){ return $e['en']; } , $en );
note how the resulting array has truncated the value for [code]
from BILL
to B
Array
(
[code] => B
[assets] => Array
(
[labels] => Array
(
[datestamp] => April 30, 2013
)
[data] => Array
(
[Equity] => 88.83000000000
[Global] => 10.84000000000
[Other] => 0.33099095766
)
)
)
Any tips on how to avoid that from happening. It is removing the array with the key [en]
as required, but I don't want the value for [code]
to be truncated.
Thanks.
You could perform type checking:
$en = array_map(function ($e){
if (is_array($e)) {
return $e['en'];
} else {
return $e;
}
} , $en );
Although it might suffice to do just this:
$en['assets'] = $en['assets']['en'];