MySQL WHERE来自一个数组

I have an array with these values, 1 & 5 and I am trying to generate a mysql query to return all of these values id, I hope that makes sense, here is my code:

if(isset($filterOpts['location'])){
                        foreach($filterOpts['location'] as $row => $value){
                                $where .= " AND `rb_locations`.`locationId` = " . $value;
                        }
                }

this will return AND rb_locations.locationId = 1 AND rb_locations.locationId = 5

I am guess that AND and AND are causing my problems. how do I fix this? When I remove the 5, it returns results.

I didnt post the rest of the query because I know its not the issue :)

Any suggestions on how to fix this?

Try using the IN clause. It checks whether a value is within a set of values:

if (isset($filterOpts['location'])) {

   $locationIds = implode(',', $filterOpts['location']);

   $where .= " AND `rb_locations`.`locationId` IN (" . $locationIds . ") ";

}