array ( [0] = array ( [Amount] => 1 [Measurement] => Cup [Ingredient] => Sugar [Notes] => Some comments ) [1] = array ( [Amount] => 2 [Measurement] => Cups [Ingredient] => Flour [Notes] => Some comments ))
array ( [0] = array ( [amount] => 1 [measurement] => Cup [ingredient] => Sugar [notes] => Some comments ) [1] = array ( [amount] => 2 [measurement] => Cups [ingredient] => Flour [notes] => Some comments ))
<?php$i = array( array( 'Amount' => 1, 'Measurement' => 'Cup', 'Ingredient' => 'Sugar', 'Notes' => 'Some comments' ), array( 'Amount' => 2, 'Measurement' => 'Cups', 'Ingredient' => 'Flour', 'Notes' => 'Some comments' ));$key = array_keys($i);foreach($key as $ki){ $klower = strtolower($ki); $val = $i[$ki]; if(is_array($val)){ foreach($val as $kinner => $vinner){ $tl = strtolower($kinner); unset($val[$kinner]); $val[$tl] = $vinner; } } unset($i[$ki]); $i[$klower] = $val;}?>
<?php $a = array( array( 'Amount' => 1, 'Measurement' => 'Cup', 'Ingredient' => 'Sugar', 'Notes' => 'Some comments' ), array( 'Amount' => 2, 'Measurement' => 'Cups', 'Ingredient' => 'Flour', 'Notes' => 'Some comments' ) ); function strToLowerArray ( $vals ) { return strtolower( $vals ); } foreach( $a as $arr ) { $b[] = array_map("strToLowerArray", $arr); } print_r($b);?>
<?php $a = array( array( 'Amount' => 1, 'Measurement' => 'Cup', 'Ingredient' => 'Sugar', 'Notes' => 'Some comments' ), array( 'Amount' => 2, 'Measurement' => 'Cups', 'Ingredient' => 'Flour', 'Notes' => 'Some comments' ) ); foreach( $a as $arr ) { print_r(array_change_key_case($arr, CASE_LOWER)); echo '<br />'; }?>
function arrIndexLowerCase($arr = null){ $arr = array_change_key_case($arr,CASE_LOWER); $newArr = $arr; foreach ($arr as $k => $v){ if (is_array($v)){ $newArr[$k] = $this->arrIndexLowerCase($v); } } return $newArr; }
recursive function will do the magic tricks for multi-arrays, as stated above.
Old post but you don't even need to copy the array
function array_change_key_case_recursive($input, $case = null) { $case = $case ?: CASE_LOWER; $input = array_change_key_case($input, $case); foreach ($input as $key => $val) { if (is_array($val)) $input[$key] = array_change_key_case_recursive($val, $case); } }
I'm trying to get it so that the keys switch to lowercase like:
Doesn't seem to work with array_change_key_case?
seems to work like a charm
Credit: http://www.php.net/manual/en/function.array-change-key-case.php#106233
Edit: Oh you said the KEY should be lowercase...
recursive function will do the magic tricks for multi-arrays, as stated above.
Old post but you don't even need to copy the array