$ids = array(1,2,3);
$in = implode(',',$ids);
$query = "SELECT * FROM user where user_id IN ($in) ";
Query works no problem. But when $ids is empty array $ids = array();
I got sql query error rightly so because SELECT * FROM user where user_id IN () is not a valid query .
How can I avoid such situation without checking for empty array i.e making query run no matter what ?
Best way to manage this is:
This saves you from if/else structure and everything else