Re: [php-49] Using colon instead of curly-braces { } with conditionals

From: m.
Sent on: Thursday, March 19, 2009 6:00 PM
As expressed in the comments the colon syntax best fits when mixing HTML and PHP and control strucutres.

I don't know if this is the most efficient way to do this but I often use:

<?php if($some_array){ foreach($array as $k => $v): ?>
  <h1>some title</h1>
  <p><?php echo $k?>: <?php echo $v?></p>
<?php endforeach;}?>

(wow that was a pain to tap out on an iPhone)
On Mar 19, 2009, at 5:43 PM, David Malouf <[address removed]> wrote:

Came across this blog entry and it got me wondering...

The premise of the article is that when code gets big and nested, using curly-braces can get troublesome.  Instead, PHP can handle a colon followed by an END__

For example:
    if ($something == 'true') :
        $aBunchOfCodeHere = 'yes';

Using NetBeans (like Eclipse and I'm assuming other IDEs) means I can 'see' what conditional/line each closing-curly-brace  }   is associated with.

Since I'm curious, though, I'm wondering if there is ever a time when any of y'all use the colon method?


Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by David Malouf ([address removed]) from The Seattle PHP Meetup Group.
To learn more about David Malouf, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup Support: [address removed]
632 Broadway, New York, NY 10012 USA

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy