fluidsharp Posted January 9, 2010 Share Posted January 9, 2010 Hello! Please tell what does it mean, and how it works: $device = is_null($coffeeMaker) ? "hands" : $coffeeMaker; What do mean "?" and ":" there? It is regular expression? <?php function makecoffee($types = array("cappuccino"), $coffeeMaker = NULL) { $device = is_null($coffeeMaker) ? "hands" : $coffeeMaker; return "Making a cup of ".join(", ", $types)." with $device.\n"; } echo makecoffee(); echo makecoffee(array("cappuccino", "lavazza"), "teapot"); ?> Quote Link to comment Share on other sites More sharing options...
p2grace Posted January 9, 2010 Share Posted January 9, 2010 That syntax is called shorthand or ternary if/else statements. Explanation: http://snippets.dzone.com/posts/show/76 Basically it's saying set $device equal to "hands" if $coffeeMaker is null, otherwise set it to the value of $coffeeMaker. Quote Link to comment Share on other sites More sharing options...
trq Posted January 9, 2010 Share Posted January 9, 2010 Take a look at the ternary operator. Its basically a small if statement that is equivalent to.... if (is_null($coffeeMaker)) { $device = "hands"; } else { $device = $coffeeMaker; } Quote Link to comment Share on other sites More sharing options...
fluidsharp Posted January 11, 2010 Author Share Posted January 11, 2010 Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.