array_search function in php

41

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

$key = array_search(3, array_column($users, 'user_id'));

$userName = $users[$key]['first_name'];
$value = array_search("Ben",$firstnameArray);

Comments

Submit
0 Comments