array_search in php
snippet in php

array_search in php

user1597


<?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;
?>

how to search for a value in an array php

user5500

<?php 
// PHP function to illustrate the use of array_search() 
function Search($value, $array) 
{ 
    return(array_search($value, $array)); 
} 
$array = array("ram", "aakash", "saran", "mohan", "saran"); 
$value = "saran"; 
print_r(Search($value, $array)); 
?> 

array_search in php

user2664

<?php
$a = [
'Canceled' => 1,
'Traded / Filled'=> 2,
'(Not used currently)'=> 3,
'Transit'=> 4,
'Rejected'=> 5,
'Pending'=> 6,
];
echo array_search("5",$a);
?>