Example 1: check if array has value php
$myArr = [38, 18, 10, 7, "15"];
echo in_array(10, $myArr);
echo in_array(19, $myArr);
echo in_array("18", $myArr);
echo in_array("18", $myArr, true);
Example 2: array_search in php
<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array);
$key = array_search('red', $array);
?>
Example 3: array_search
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');
}
Example 4: search php array
$userdb = array(
array(
'uid' => '100',
'name' => 'Sandra Shush',
'pic_square' => 'urlof100'
),
array(
'uid' => '5465',
'name' => 'Stefanie Mcmohn',
'pic_square' => 'urlof100'
),
array(
'uid' => '40489',
'name' => 'Michael',
'pic_square' => 'urlof40489'
)
);
Example 5: 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);
?>