1<?php
2$array = array(
3 'fruit1' => 'apple',
4 'fruit2' => 'orange',
5 'fruit3' => 'grape',
6 'fruit4' => 'apple',
7 'fruit5' => 'apple');
8
9$keys = array_keys($array); // return array
10$values = array_values($array); // return array
11?>
1$array = array(0 => 100, "cor" => "vermelho");
2print_r(array_keys($array));
3
4$array = array("azul", "vermelho", "verde", "azul", "azul");
5print_r(array_keys($array, "azul"));
6
7$array = array("cor" => array("azul", "vermelho", "verde"),
8 "tamanho" => array("pequeno", "medio", "grande"));
9print_r(array_keys($array));
10
1<?php
2$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
3foreach($age as $x=>$x_value)
4 {
5 echo "Key=" . $x . ", Value=" . $x_value;
6 echo "<br>";
7 }
8?>
1
2<?php
3$array = array(
4 'fruit1' => 'apple',
5 'fruit2' => 'orange',
6 'fruit3' => 'grape',
7 'fruit4' => 'apple',
8 'fruit5' => 'apple');
9
10// this cycle echoes all associative array
11// key where value equals "apple"
12for($i = 0; $i< sizeof($array);$i++){
13if (key($array[$i]) == 'apple') {
14 echo key($array).'<br />';
15 }
16 //next($array);
17}
18?>
19
20
1
2<?php
3$array = array(
4 'fruit1' => 'apple',
5 'fruit2' => 'orange',
6 'fruit3' => 'grape',
7 'fruit4' => 'apple',
8 'fruit5' => 'apple');
9
10// this cycle echoes all associative array
11// key where value equals "apple"
12while ($fruit_name = current($array)) {
13 if ($fruit_name == 'apple') {
14 echo key($array).'<br />';
15 }
16 next($array);
17}
18?>
19
20