What does this syntax ( page = $page ? $page : ‘default’ ) in PHP mean?

I’m new to PHP. I came across this syntax in WordPress. What does the last line of that code do?

$page = $_SERVER['REQUEST_URI'];
$page = str_replace("/","",$page);
$page = str_replace(".php","",$page);
$page = $page ? $page : 'default'

Related posts

Leave a Reply

7 comments

  1. It’s a ternary operation which is not PHP or WordPress specific, it exists in most langauges.

    (condition) ? true_case : false_case 
    

    So in this case the value of $page will be “default”, when $page is something similar to false — otherwise it will remain unchanged.