Skip to content

Instantly share code, notes, and snippets.

@yaodong
Last active August 29, 2015 14:19
Show Gist options
  • Save yaodong/7a06597d30ceb1ad89c0 to your computer and use it in GitHub Desktop.
Save yaodong/7a06597d30ceb1ad89c0 to your computer and use it in GitHub Desktop.
Set Variable Default Value in PHP

In PHP, You can set default value for variables use ?: if value contains fasle value or undefined.

$value = null;
$value = $value ?: "default";
echo $value; // get "default"

Another way is:

$value || $value = 'default';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment