Hi,
I got the following code for changing the case of associative array. Its working fine on single dimensional array. I think it should work on 2d array but when I am trying to process the 2d array, I am getting the following output:
Actual array
Values are in lower case.
Array ( )
Values are in upper case.
Array ( )
The code is given below:
<?php
function array_change_value_case($input, $ucase)
{
$case = $ucase;
$narray = array();
if (!is_array($input))
{
return $narray;
}
foreach ($input as $key => $value)
{
if (is_array($value))
{
$narray[$key] = array_change_value_case($value, $case);
echo "Comes here";
continue;
}
$narray[$key] = ($case == CASE_UPPER ? strtoupper($value) : strtolower($value));
}
return $narray;
}
//$Color = array('A' => 'Blue', 'B' => 'Green', 'c' => 'Red');
$anotherAssocMDArr = array(
"first player" => array("name" => 'John', "age" => 'twenty five'),
"second player" => array("name" => 'Tim', "age" => 'thirty five')
);
echo 'Actual array '.'<BR>';
print_r($Color);
echo '<BR>'.'Values are in lower case.'.'<BR>';
$myColor = array_change_value_case($Color,CASE_LOWER);
print_r($myColor);
echo '<BR>'.'Values are in upper case.'.'<BR>';
$myColor = array_change_value_case($Color,CASE_UPPER);
print_r($myColor);
?>
Somebody please guide me how I can modify the above program for 2d arrays.
Zulfi.