I am creating a basic function that builds Mysql WHERE clauses based on how many of them are in the array.
$array = array('id' => '3', 'name' => 'roger'); $sql = "SELECT * FROM table WHERE "; foreach ($array as $k => $v) { $sql .= $k . ' = ' . $v . ' AND '; }
which will output
SELECT * FROM table WHERE id = 3 AND name = roger AND
However, obviously, I donβt want the latter And, how can I remove it from the string?
thanks
source share