Jump to content

Alternate syntax


justsomeguy
 Share

Recommended Posts

I found that there is alternate syntax for a lot of different control statements. All of these examples work, they are taken from Programming PHP:

if ($user_validated):  echo "Welcome!";else:  echo "Access forbidden!";endif;switch ($uname):  case 'ktatroe':    //do something    break;  case 'rasmus':    //do something    break;  case 'petermac':    //do something    break;endswitch;while ($i <= 10):  $total += $i;  $i++;endwhile;for ($i = 1; $i <= 10; $i++):  $total += $i;endfor;foreach ($array as $key => $value):  // ...endforeach;

Just something I didn't realize, I don't think I've ever seen this used in an example.

Link to comment
Share on other sites

Just something I didn't realize, I don't think I've ever seen this used in an example.
The non use of curly brakets :) I've never seen that either, it's like asp'ish :)
Link to comment
Share on other sites

It's like VB, you can also use Javascript to write ASP.

That's true, i stick to vbscript with asp though :) Hasn't vb been replaced by .net?I prefer the use of curly brakets though, i find it easier to visualise where structures begin/end. Maybe it's just the order i learnd languages though, others may find curly brackets weird.
Link to comment
Share on other sites

  • 4 weeks later...

I don't know if there is an old or a new, maybe when the Zend engine first came out they changed the syntax, but it is definately useful for this type of thing:

<?php if ($something): ?>.........<?php else: ?>.........<?php endif; ?>

That just looks a little cleaner then using brackets. But I haven't seen much syntax for php versions 1 or 2, they changed a lot of things for version 3 when they added Zend.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...