<?php
$array = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple');
// this cycle echoes all associative array
// key where value equals "apple"
for($i = 0; $i< sizeof($array);$i++){
if (key($array[$i]) == 'apple') {
echo key($array).'<br />';
}
//next($array);
}
?>
/*
|===============================================================
| How to get keys of associative array php
|===============================================================
*/
//------ Method-1 -------
$countries = ["Pakistan" => "+92", "India" => "+91", "Qatar" => "+974"];
$country_codes = (array_keys($countires));
dd($country_codes);
//------ Method-2 -------
$countries = ["Pakistan" => "+92", "India" => "+91", "Qatar" => "+974"];
$country_codes = collect($countires)->keys();
dd($country_codes);