1<?php
2$search_array = array('first' => 1, 'second' => 4);
3if (array_key_exists('first', $search_array)) {
4 echo "The 'first' element is in the array";
5}
6?>
7
1
2<?php
3$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
4
5$key = array_search('green', $array); // $key = 2;
6$key = array_search('red', $array); // $key = 1;
7?>
8
9
1$arr = array(
2 "one" => 1,
3 "two" => 2,
4 "three" => 3,
5 "seventeen" => 17
6);
7function find($mot){
8
9 global $arr; // this is global variable
10 $ok=false;
11 foreach ($arr as $k => $v)
12 {
13 if($k==$mot){
14 return $v; $ok=true; // or return true;
15 }
16 }
17 if(ok==false){ return -1; } // or return false;
18}
19
20//call function
21echo find("two");