How to use ternary operator instead of if-else in PHP

Posted by Mac Taylor on Stack Overflow See other posts from Stack Overflow or by Mac Taylor
Published on 2010-04-24T15:58:52Z Indexed on 2010/04/24 16:13 UTC
Read the original article Hit count: 402

Filed under:
|

hey guys

i need to shorten or better to say ., harden my codes

this is my original code :

if ($type = "recent") {
    $OrderType =  "sid DESC";
}elseif ($type = "pop"){
    $OrderType =  "counter DESC";
}else {
    $OrderType =  "RAND()";
}

now how can i use markers like this :

$OrderType = ($type = "recent") ? "sid DESC" : "counter DESC" ;

i tried but i didnt know how to write elseif in operators

© Stack Overflow or respective owner

Related posts about php

Related posts about operators