PHP assignment with a default value PHP assignment with a default value php php

PHP assignment with a default value


In PHP 5.3, you can also do:

  $a = f() ?: 'default';

See the manual on ?: operator.


This seems to work fine:

$x = f() or $x = 'default';


function f(){  // conditions   return $if_something ? $if_something : 'default';}$x = f();