is there a 'if' function something like
if $variable=("")
include ("blah.php")
to show a certain page or echo something if a variable isn't defined
if-variable isnt defined?
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can use either empty() (as lc said) or isset() the difference between them being that a variable will be considered 'empty' if it is,
but a variable will be considered 'set' if it has any value including an empty string or 0.
So to use empty() you would use something like lc's example and to use isset() you would do something like:
In looking for an undefined variable I personally would use isset() but you can pick whichever you feel is more appropriate.
Mac
Code: Select all
$var = '';
// or
$var = 0;So to use empty() you would use something like lc's example and to use isset() you would do something like:
Code: Select all
if (!isset($variable)) {
include 'blah.php';
}Mac