Answers for "find in array in php"

PHP
4

php search on array

//array_search
$result = array_search("apple", $fruit_array); // return index or false

//in_array
$result = in_array("apple", $fruit_array); // return true or false
Posted by: Guest on July-05-2021
1

array_search

// array demo

public $gender = array(
  1 => 'Male',
  2 => 'Female',
  3 => 'Other',
);

$gen = 1;

if ($gen == array_search('Male', $this->gender)) {
  $gender = __d('member', 'male');

} elseif ($gen  == array_search('Female', $this->gender)) {
  $gender = __d('member', 'female');

}
Posted by: Guest on October-02-2020

Browse Popular Code Answers by Language