Page 1 of 1

Setting an undefined value

Posted: Sat Aug 24, 2002 3:54 pm
by Bennettman
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.

Posted: Sat Aug 24, 2002 3:55 pm
by Takuma
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
}

Posted: Sat Aug 24, 2002 4:28 pm
by hob_goblin
uhm... that was not what he wanted to do...

use an if statement, and the function isset

if(!isset($content)){
$content = "index stuff";
}

Posted: Sat Aug 24, 2002 4:49 pm
by volka
or

Code: Select all

if (!defined('MY_DEFINE'))
  define('MY_DEFINE', 'my_value');
...
print(MY_DEFINE);
this would be a constant

Posted: Mon Aug 26, 2002 8:55 am
by Bennettman
Mmkay, gotcha. So !isset is basically "is not set", with the ! sign...

Cheerz :) ::drinks Coke::

Posted: Wed Aug 28, 2002 10:09 am
by gotDNS

Code: Select all

if(!$content) { code; }

Posted: Wed Aug 28, 2002 10:14 am
by hob_goblin
It's sloppy to do that..

Posted: Wed Aug 28, 2002 10:15 am
by volka
1) PHP Notice: Undefined variable: content in xyz.php on line xyz

2)

Code: Select all

<?php
$content = '0';
if(!$content)
    print('content not set');
?>