Daniel K. Theemann

Proud dad to Frida, a UEFA A student and football coach.

  • Home
  • Coaching CV
  • Coaching drills
  • Projects
  • Contact
  • Credits
  • Medias
    • Geusselt Cup 2011
  • KFC U14 (Forår 2012)
Twitter RSS

<variable> = <expression> ? <value> : <value>

Posted on 15.04.2007 by Daniel K. Theemann
1 CommentLeave a comment
[Translate]

We all know that you as a programmer often is in a situation, where you proberly use an if-else construction. But you don’t always have to, often it is more sophisticated to use the sentence from the title and assign the right value, when the variable is instantiated.

<variable> = <expression> ? <value> : <value>

Let me give an example “when the sky is dark, then daytime is night, otherwise daytime is day”.

[source:php]
< ?php

$sky = “Dark”;

if(strcmp($sky, “Dark”) == 0) {
$day_time = “Night”;
}
else {
$day_time = “Day”;
}

?>
[/source]

The piece of code where you assign a value to “day_time” could you easily write on line:

[source:php]
< ?php

$sky = “Dark”;

$day_time = strcmp($sky, “Dark”) == 0 ? “Night” : “Day”;

?>
[/source]

So keep this little trick in mind, whenever a variable can be assigned one of two possible values.

Possibly Related Posts:

  • Yay, going to the IPC 2008!
  • Light-weight PHP engine for BPEL based on XML-rewriting
  • Diploma Project handed in, Yay!
  • Understanding the PHP object model (slides)
  • What PHP IDE to choose? There are so many out there….

Tags: PHP
Categories: PHP | Tags: PHP
Notice: This work is licensed under a BY-NC-SA. Permalink: <variable> = <expression> ? <value> : <value>
My laptop now runs Ubuntu 7.04
Passed [DSDS]

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

*


question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Recent Posts

    • M2: Kolding FC (3 – 4) Varde IF
    • Pokal: Kolding FC (0 – 2) Esbjerg fB
    • M2: Kolding FC (2 – 1) Vejen SF
    • M2: Hjerting IF (2 – 5) Kolding FC
    • M2: Ølgod IF (5 – 2) Kolding FC
  • TWEETS…

    Daniel: We had the play and Chelsea had the luck tonight. A very disappointing season for us. 3 times no. 2. #fcbayern
    1 day ago
    Daniel: Come on Bayern. Finish it and let the CL trophy stay in Munich after the final whistle. #fcbayern #cl
    1 day ago
    Daniel: New Blog Post - M2: Kolding FC (3 - 4) Varde IF. Read it now at http://t.co/l74n6Yhq #coachingfamily
    6 days ago
  • Topics

    1v1 offensive aabk awards bpel build-up play christmas coaching Conferences Cycling dbu Diploma IT drills football geusselt-cup-2011 grassroots java jm kolding FCU laptop Linux motivation MySQL Personal PHP pokal possession play pressing recovery Soccer svn switch of play tactics theemann.dk U12 U13 U14 ubuntu uefa wing play work Youth development
  • Last read

    ISBN: 1905928084
  • Who's Online

    0 visitors online now
    0 guests, 0 members
© Daniel K. Theemann. Proudly Powered by WordPress | Nest Theme by YChong
English English powered byGoogle