find a value in array in php code example
Example 1: 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!!!";
}
?>
Example 2: php value in array
in_array ( mixed $needle , array $haystack , bool $strict = false ) : bool
Example 3: in_array in php
in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : bool
echo in_array("18", $myArr);
echo in_array("18", $myArr, true);
Example 4: find element in arrat php
$userdb=Array
(
(0) => Array
(
(uid) => '100',
(name) => 'Sandra Shush',
(url) => 'urlof100'
),
(1) => Array
(
(uid) => '5465',
(name) => 'Stefanie Mcmohn',
(pic_square) => 'urlof100'
),
(2) => Array
(
(uid) => '40489',
(name) => 'Michael',
(pic_square) => 'urlof40489'
)
);
simply u can use this
$key = array_search(40489, array_column($userdb, 'uid'));