要获取基于位置的用户列表,我在foreach中使用foreach和in_array。但它只返回一行,DB中有很多行。这是否正确?
$users_list = [];
foreach ($users as $key => $value) {
$user_selected_locations_list = array("hyderabad", "mumbai");
if(in_array($value['user_location'], $user_selected_locations_list)){
array_push($users_list, $value);
}
}
echo json_encode($users_list);
海德拉巴有数百名用户,但我在$ users_list数组中只有一名用户
$users = Array
(
[0] => Array
(
[user_id] => 245
[user_name] => Jessica Alba
[user_gender] => Female
[user_location] => hyderabad
)
[1] => Array
(
[user_id] => 246
[user_name] => Kristen
[user_gender] => Female
[user_location] => hyderabad
)