Setting an undefined value
Moderator: General Moderators
-
Bennettman
- Forum Contributor
- Posts: 130
- Joined: Sat Jun 15, 2002 3:58 pm
Setting an undefined value
Basically, I want to have a value $content set to a certain value if it's not already defined. The only real situation I need this for is viewing the homepage when someone goes straight to index.php with no definition for $content.
Use unset($variable) to set variable undefined. -> This is wrong....
Code: Select all
if(!isset($content) || strlen(trim($content)) {
//Action for undefined $content
} else {
//Action for defined $content
}
Last edited by Takuma on Mon Aug 26, 2002 2:44 pm, edited 2 times in total.
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
orthis would be a constant
Code: Select all
if (!defined('MY_DEFINE'))
define('MY_DEFINE', 'my_value');
...
print(MY_DEFINE);-
Bennettman
- Forum Contributor
- Posts: 130
- Joined: Sat Jun 15, 2002 3:58 pm
Code: Select all
if(!$content) { code; }- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
1) PHP Notice: Undefined variable: content in xyz.php on line xyz
2)
2)
Code: Select all
<?php
$content = '0';
if(!$content)
print('content not set');
?>