yphastos
9/1/2017 - 2:45 PM

convert array keys to lowercase

convert array keys to lowercase

// just for fun, because there already is a native function:
// array array_change_key_case( array $array [, int $case = CASE_LOWER ] ) // || CASE_UPPER

function _array_keys_lower($datos){
    // convertir keys de MAY a min
    foreach($datos as $k => $v){
    	if($k == 0){
    		$cols = array_keys($v);
    		// pr($cols,"cols");
    		$Mm = array();
    		foreach($cols as $c => $col){
    			$Mm[$col] = strtolower($col);
    		}
    		// pr($Mm,"Mm");
    	}
    
    	foreach($Mm as $M => $m){
    		$datos[$k][$m] = $v[$M];
    		unset($datos[$k][$M]);
    	}
    
    }
    return $datos;
}