C3rd
[PHP] Shortcuts of If-Else statement
Posted: 5 Apr 2009, 16:58pm - Sunday
When I learn PHP last September 2005, I was little bit confuse in PHP if-else statement... especially a statement contains with ? and : but somehow, I got it right. I post this cause somebody ask again what's the difference. So told him, its all the same and its just a shortcuts.
<?php
$authenticated = true;
// [1] standard if-else statement
if ($authenticated)
{
echo 'YES';
}
else
{
echo 'NO';
}
// same with [1] :P
if ($authenticated) { echo 'YES'; } else { echo 'NO'; }
// [2] lil bit shortcut
if ($authenticated)
echo 'YES';
else
echo 'NO';
// [3] the shortcut
echo $result = ($authenticated) ? 'YES' : 'NO';
?>
Or let me say its an evolution of if-else statement... Hahaha.. or maybe the laziness of the programmer. :P So got it? hehehehe..
Search
Categories
Related Links
- Apache Web Server
- ASP Immigration Services Ltd.
- CentOS Linux
- Color Scheme Picker
- CSS Button Generator
- Deviant Art Account
- Don Tabaniag - GraphiCult
- Jerson Maglasang Weblog
- Joshua Manlunas
- Mark "mungkey" Vicente
- Matt Arnilo Baluyos
- MySQL
- Paul Labis
- PHP
- PrendStar
- Ridvan Baluyos
- Scott Davies
- SEO Fart XML-RPC Ping Tool
- Stripes Generator
- The Hero
- Ubuntu Linux
- Vim Carlo Nabora (DA)
- Wella Maria Hong
- What is my IP?
- Xavier University - Ateneo de Cagayan
- Zabyer Community