jueves, 5 de diciembre de 2024

applying a call back function to all keys on an array.

 $array1 = array('blue'  => 1, 'red'  => 2, 'green'  => 3, 'purple' => 4);


$array2 = array('green' => 3, 'blue1' => 1, 'yellow' => 7, 'cyan'   => 8);



function test($n,$search_array){

return  array_key_exists($n, $search_array); 

}



echo "<br>";

print_r(array_map('strtoupper',array_keys($array1)));  

// will print Array ( [0] => BLUE [1] => RED [2] => GREEN [3] => PURPLE )


echo "<br>";


echo test('yellow',$array2);   //  echo 1




No hay comentarios:

Publicar un comentario