PHP array_keys()


array_keys() retrieves all keys of an associative array.

<?PHP
	$arr=array("apple"=>"carbon","rice"=>"carbon","nuts"=>"fat","meat"=>"protein");
    $arr2=array_keys($arr);
	foreach($arr2 as $element) echo "$element, "; //apple, rice, nuts, meat, 
?>

If a value is supplied, only keys with the value will be retrieved.
<?PHP
	$arr=array("apple"=>"carbon","rice"=>"carbon","nuts"=>"fat","meat"=>"protein");
    $arr2=array_keys($arr,"carbon");
	foreach($arr2 as $element) echo "$element, "; //apple, rice, 
    $arr2=array_keys($arr,"fat");
	foreach($arr2 as $element) echo "$element, "; //nuts,  
?>