Skip to main content

Shorthand for isset() in php

  • NULL coalescing operator in php

    $var = $var ?? "default";

    You can use this snippet as a shorthand for isset() function in php which is a NULL coalescing operator. It is used to check whether a given variable is NULL or not and returns its first operand if it exists and is not NULL else it returns the second operand. It will fetch the value of $var and returns 'default' if it ($var) does not exist. 

    Instead of writing any lengthy code like $var = isset($var) ? $var : 'default';  you can use this code snippet.

  • Back to code snippet queries related php