array search by key in php

PHP
<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');

$key = array_search('green', $array); // $key = 2;
$key = array_search('red', $array);   // $key = 1;
?>

$arr = array(
    "one" => 1,
    "two" => 2,
    "three" => 3,
    "seventeen" => 17
);
function find($mot){
  
  global $arr; // this is global variable
  $ok=false;
 foreach ($arr as $k => $v) 
    {
      if($k==$mot){
        return $v; $ok=true; // or return true;
      }
    }
  if(ok==false){ return -1; }  // or return false;
}

//call function
echo find("two");
Source

Also in PHP: