I have an array with the following structure:
Array
(
[0] => Array
(
[animal] => dog
[color] => black
)
[1] => Array
(
[animal] => cat
[color] => white
)
[2] => Array
(
[animal] => mouse
[color] => grey
[attributes] => Array
(
[nickname] => snuggles
[nickname] => buddy
)
)
)
I now need to execute a function on every value in the attribute array. So for example capitalize SNUGGLES
and BUDDY
.
This is my approach:
$array = array(
array("animal"=>"dog","color"=>"black"),
array("animal"=>"cat","color"=>"white"),
array("animal"=>"mouse","color"=>"grey", "attributes" => array("nicknames" => "snuggles", "nicknames" => "buddy"))
);
foreach ( $array as $key => $value ) {
foreach ( $value as $key1 => $value1 ) {
if ($key1 == 'attributes') {
foreach ( $value as $key2 => $value2 ) {
$value2 = strtoupper($value2);
$array [$key] [$key1] [$key2]= $key2;
}
}
}
}
But I get this error:
strtoupper() expects parameter 1 to be string, array given in ...