array search for associate array code example
Example 1: array search by key in php
$arr = array(
"one" => 1,
"two" => 2,
"three" => 3,
"seventeen" => 17
);
function find($mot){
global $arr;
$ok=false;
foreach ($arr as $k => $v)
{
if($k==$mot){
return $v; $ok=true;
}
}
if(ok==false){ return -1; }
}
echo find("two");
Example 2: array_search in php
<?php
$a = [
'Canceled' => 1,
'Traded / Filled'=> 2,
'(Not used currently)'=> 3,
'Transit'=> 4,
'Rejected'=> 5,
'Pending'=> 6,
];
echo array_search("5",$a);
?>