I'm building a basic function, which builds out Mysql WHERE clauses based on how many 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 that last AND, how do I go about removing it from the string?
Thanks