<?php
$array = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple');
$keys = array_keys($array); // return array
$values = array_values($array); // return array
?>
$array = array(0 => 100, "cor" => "vermelho");
print_r(array_keys($array));
$array = array("azul", "vermelho", "verde", "azul", "azul");
print_r(array_keys($array, "azul"));
$array = array("cor" => array("azul", "vermelho", "verde"),
"tamanho" => array("pequeno", "medio", "grande"));
print_r(array_keys($array));
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
foreach($age as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
<?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);
}
?>