Hi Nick,

Apart from what others said about reassigning a variable within the loop, I
always find it most useful to properly indent code, so to be able to count
(curly) brackets.

See the difference:

Yours:
foreach ($outarr as $val) {
  if(strpos($val,"http://";) === 0){
     $val = '<a href="' . $val . '">' . $val . '</a>';
  }elseif(strpos($val,"ftp://";) === 0){
     $val = '<a href="' . $val . '">' . $val . '</a>';
  }else{
     $val = $val;
  }
}

Mine:
foreach ($outarr as $val) {
   if (strpos($val,"http://";) === 0) {
      $val = '<a href="' . $val . '">' . $val . '</a>';
   } else {
      if (strpos($val,"ftp://";) === 0) {
         $val = '<a href="' . $val . '">' . $val . '</a>';
      } else {
         $val = $val;
      }
   }
}

In mine there are three curly brackets after the last assignment vs two in
yours...

Usually I digit these kind of things like:
if () {
} else {
}

and then start filling in the condition and blocks, as even with a good
code-aware editor errors are easily made.

By the way: I also don't get the purpose of your loop as $val will
ultimately only have a value related to the last element in the loop. And
not to all. This of course, assuming you want to create a list of links
derived from $outarr, and not just a single link.

Marc



Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/php-list/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to