www.webdeveloper.com
Results 1 to 2 of 2

Thread: What is this ?false:true thing?

  1. #1
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357

    What is this ?false:true thing?

    Look at this code:

    PHP Code:
    $resolve='whatever you want to put here';

    if (
    is_string($resolve))
    {
       
    $resolve = (preg_match('/false|no|off/i'$resolve))?false:true;
        


    If I var_dump $resolve after this, and it contains the word "false", "no" and/or "off" I get bool(false) Otherwise I get bool(true). How exactly is it doing that, though? What role does "?false:true" play in this?

    I want to know what this is, it looks handy.
    Last edited by evenstar7139; 07-26-2012 at 12:37 AM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,617
    ternary operator

    PS: Please use with moderation, saving it for simple usages where it's easy to read. For more complex cases, a standard and indented if/else block will make your life easier when maintaining your code in the future.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles