function findNeedle($haystack) {
  foreach($haystack as $key => $value){
    if($value === "needle"){
      return "found the needle at position " . $key;
    }
  }
 
}

ou bien

function findNeedle($a) {
  return "found the needle at position " . array_search("needle", $a);
}
Catégories : PHP