Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts

    short code syntax

    can someone tells me what does this means?

    $length = $len >= 0? $len: count($array);

    thanks

  • #2
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it is the ternary operator. usually simplifies if-then's, but don't overuse it.

    the example you posted is equivalent to this:
    Code:
    if ($len>=0) {
        $length = $len;
    } else {
        $length = count($array);
    }
    some site with more info
    http://www.totallyphp.co.uk/tutorial..._operators.htm

  • #3
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you start to use it, I think it looks more readable if you write it as
    PHP Code:
    $length = ($len >= 0) ? $len count($array); 

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow. thanks alot.


  •  

    Posting Permissions

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