PHP - What you may not know about IF statements, ternary operators explained.
Search
Tag Search
flash
client-side
svn
disable cache
htaccess
regular expressions
car
thickbox
regex
art
action script
subdomain
cache
bugs
seo
plugin
hand drawing
php
javascript
html
AJAX
apache
jquery
301 redirect
print design
Recently Added
- HTML [3 items]
- SVN (Subversion) [3 items]
- jQuery [10 items]
- PHP [4 items]
Most Popular
- jQuery [10 items]
- PHP [4 items]
- SVN (Subversion) [3 items]
- HTML [3 items]
Member Options
12
Nov
Created by: robilim - Date Added: 12th November 2009 - 0 Responses
Traditional IF statements can take up more lines than you would like to. Especially when its only a small condition. Ternary operators take three arguements condition, true, false. This can be contructed on one line as opposed to the tranditional way which can take 4 lines (to look nice to read).
(condition) ? true : false;
A traditional statement may look like this:
if(is_numeric($_GET['id'])){ $id = $_GET['id'];}else{ $id = 0;}The same statement as a ternary operator:
$id = is_numeric($_GET['id'])? $_GET['id'] : 0;

