Develop PHP Website for Learning Web Design Free Online
  Home   |   Forums   |   DevCMS
  Join   |   Log In
 
   

PHP Tutorials - Learn PHP

Tutor at Develop PHP
The ?(ternary) Operator
By: Adam      Created: Jul 14, 2009      Views: 2252 Tweet This Page  Post page to Facebook  Post page to Facebook

There is an operator in PHP that is very similar in functionality to the if statement called the ternary (?) conditional operator. It evaluates to check if the first subexpression is true, if it is it will return the value of the second subexpression, if the first subexpression is false it will return the value of the third subexpression.

Here is a code example using flavor variables and checking to see if the shop has our favorite flavor using ?:
Learn HTML
<?php
// Let's say our choice is chocolate
$flavor_choice "chocolate";
// And we do not know it yet but all they have is vanilla
$output = ($flavor_choice == "vanilla") ? "Yes, we have vanilla." "Sorry we do not have $flavor_choice.";
// output the appropriate subexpression
echo "$output";
?>

Develop PHP browser display window
Sorry we do not have chocolate.




                                   That concludes this section, to continue learning PHP head back to the index


Comment on The ?(ternary) Operator




Search Tags:
The   ·  ?(ternary)   ·  Operator   ·  
 
 
Arbitrary Links and Archives
Home
Active Forums
Members
SIte News
Link To Us
Gear
2009 Forum Archive
Programming Courses
Learn HTML
Learn CSS
Learn PHP
Learn MySQL
Learn Javascript
Learn jQuery
Learn ActionScript 3.0
Learn Java
Learn XML
DevelopPHP Requires Flash Player
Get Adobe Flash player
___________________________________________

Terms of Use  •  Privacy  •  Admin Notes

©2010 developphp.com   |   Powered By FlashBuildingHolder