Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Short Ternary Operator

The expression (expr1) ?: (expr3) evaluates to expr2 if expr1 evaluates to empty(), and expr3 if expr1 evaluates to false.

It is a short version of the ternary operator, and it is often used to set default values in a concise way.

<?php

    $action = $_POST['action'] ?: 'default';

?>

Documentation

See Also