array_search in php
<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // $key = 2;
$key = array_search('red', $array); // $key = 1;
?>
array_search in php
<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // $key = 2;
$key = array_search('red', $array); // $key = 1;
?>
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);
?>
search function using php for database entries
$result = mysqli_query($con, "SELECT * FROM employees
WHERE first_name LIKE '%{$name}%' OR last_name LIKE '%{$name}%'");
while ($row = mysqli_fetch_array($result))
{
echo $row['first_name'] . " " . $row['last_name'];
echo "<br>";
}
mysqli_close($con);
?>
php array_search
PHP function array_search(mixed $needle, array $haystack, bool $strict = false) false|int|string
---------------------------------------------------------------------------------------------
Searches the array for a given value and returns the first corresponding key if successful.
Parameters:
mixed--$needle--The searched value.If needle is a string, the comparison is done in a case-sensitive manner.
array--$haystack--The array.
bool--$strict--[optional] If the third parameter strict is set to true then the array_search function will also check the types of the needle in the haystack.
Returns: the key for needle if it is found in the array, false otherwise.
If needle is found in haystack more than once, the first matching key is returned. To return the keys for all matching values, use array_keys with the optional search_value parameter instead.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us