$arr = array_map("remove_last_and", $arr);
function remove_last_and($el) {
return preg_replace('/\s*and\s*$/i', '', $el);
}
Example:
$arr = array("date = '2012-02-22' and time ='08:49' and",
"date = '2012-02-22' and time ='08:49' and ");
$arr = array_map("remove_last_and", $arr);
function remove_last_and($el) {
return preg_replace('/\s*and\s*$/i', '', $el);
}
var_dump($arr);
Output:
array(2) {
[0]=>
string(37) "date = '2012-02-22' and time ='08:49'"
[1]=>
string(37) "date = '2012-02-22' and time ='08:49'"
}
ps: I did not write the inline or anonymous function as I do not know what version of PHP you are using. But, as example, you can write as of php 5.3
$arr = array_map(function($el) {
return preg_replace('/\s*and\s*$/i', '', $el);
}, $arr);
ps: I do not think that use of trim or rtrim is good as it could remove the part of the query if the query is slightly different and has 'and' letters close to the end of the string.