php + return value of an index code example
Example 1: get key of array element php
$people = array(
2 => array(
'name' => 'John',
'fav_color' => 'green'
),
5=> array(
'name' => 'Samuel',
'fav_color' => 'blue'
));
$found_key = array_search('blue', array_column($people, 'fav_color'));
Example 2: 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');
}