Search code examples
phpshorthand-if

Shorthand if statement PHP


This is a really basic question and I appoligize for asking, but it would be really usefull for me to understand, so I can use this method in the future,

How would I turn

if($_GET['page']) {
  $page = $_GET['page'];
} else {
  $page = 0;
}

Into a simple 1 line shorthand result ?


Solution

  • Try :

    $page = $_GET['page'] ? $_GET['page'] : 0;