Answer the question
In order to leave comments, you need to log in
How to know if an array value is equal to a given number?
Hello!
There is an array like:
Array
(
[0] => Array
(
[status] =>
[user_id] => 39828
[birthday] => 0
[gender] => 1
)
[1] => Array
(
[status] =>
[user_id] => 39827
[birthday] => 0
[gender] => 1
)
[2] => Array
(
[status] =>
[user_id] => 38497
[birthday] => 22
[gender] => 1
)
[3] => Array
(
[status] =>
[user_id] => 37043
[birthday] => 29
[gender] => 1
)
)
Answer the question
In order to leave comments, you need to log in
Returns found occurrences
$user_id = 37043;
$res = array_filter($your_array, function($arr) use ($user_id){
return ($arr['user_id'] == $user_id);
});
Otherwise returns an empty array I think the array_filter method will suit you ( nl3.php.net/manual/en/function.array-filter.php )
That is, you get something like:
$result= array_filter($array, function($var){
return $var['user_id'] == <искомое_значение>
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question