Site menu

CodeCook.io

  • Languages
    • C
    • C++
    • CSS
    • Git
    • HTML
    • Java
    • JavaScript
    • jQuery
    • PHP
    • Python
    • Ruby
    • Scala
  • defined
  • existence
  • test
  • variable

PHP - Check variable is defined

Test whether a variable exists and is defined.

Variable name
0
498
  • Share on Facebook
  • Share on Google+
  • Share on Twitter

Check using isset

Checks whether variable is set and is not NULL.

if (isset({{name}})) {
    {{defined_body}}
} else {
    {{undefined_body}}
}
php
  • isset function

Notes

  • Considers variable set to NULL as defined.

last update: Feb. 8, 2015

0
498
  • Share on Facebook
  • Share on Google+
  • Share on Twitter

Checks for key in defined vars array.

Get local and global defined vars and check for key existence.

array_key_exists('{{name}}', get_defined_vars())
php
  • get_defined_vars
  • array_key_exists

Notes

last update: Feb. 8, 2015

Advertisement

This project is hosted on DigitalOcean, try it and support us

Related concept

  • Increment variable by one

Other language

  • Python

Random task

  • Switch
  • Merge branch into current branch
  • Create key value container
  • Box-sizing
  • Create new repository
  • Blog
  • About
  • License