Re: elegant way of doing something else the last time through a loop?
| From: | Curt Zirzow | Date: | Mon, 14 Jul 2003 14:13:24 +0000 |
| Subject: | Re: elegant way of doing something else the last time through a loop? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155084@lists.php.net to get a copy of this message | ||
Marek Kilimajer <kilimajer@webglobe.sk> wrote:
> 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;
another way to truncat the string:
$logic_len = strlen($logic);
$condition = substr($condition, 0, -($logic_len));
> >
> >$length = strlen($sql);
> >$newlen = $length - 4;
> >$sql[$newlen].= " order by name";
> >echo $sql;
> >
> >
> >
>
Curt
--