Answers for "php find in array values"

PHP
14

in_array php

<?php
$os = array("Apple", "Banana", "Lemon");
if (in_array("Apple", $os)) {
    echo "Yeah. Exist Apple";
}
if (!in_array("Buleberry", $os)) {
    echo "Oh, Don't Exist Blueberry!!!";
}
?>
Posted by: Guest on October-02-2020
2

array search by key in php

$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");
Posted by: Guest on November-04-2020

Code answers related to "php find in array values"

Browse Popular Code Answers by Language