Re: elegant way of doing something else the last time through a loop?
| From: | Marek Kilimajer | Date: | Mon, 14 Jul 2003 12:00:42 +0000 |
| Subject: | Re: elegant way of doing something else the last time through a loop? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155073@lists.php.net to get a copy of this message | ||
I always do it this way:
$condition='';
foreach ($phrases as $key=>$val) {
if (($val != "the") && ($val != "and")) {
$condition.= "name like '%$val%' $logic";
}
}
$condition=substr($condition, 0, strlen($condition) - strlen($logic));
$sql .= $condition;
$length = strlen($sql); $newlen = $length - 4; $sql[$newlen].= " order by name"; echo $sql;