<?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, ?>
<?PHP $arr=array("apple"=>"carbon","rice"=>"carbon","nuts"=>"fat","meat"=>"protein"); $arr2=array_values($arr); foreach($arr2 as $element) echo "$element, "; //carbon, carbon, fat, protein, ?>