PDA

View Full Version : boolean


King Kovifor
06-18-2006, 03:17 PM
In PHP, when I write this in a plugin:

if (THIS_SCRIPT == "index")
{
global $globaltemplates;

if ($vbulletin->$options[option] == "1")
{
$globaltemplates = array_merge($globaltemplates, array('template'));
}
if ($vbulletin->$options[option] == "0")
{
$globaltemplates = array_merge($globaltemplates, array('second_template'));
}
}

What would be the $vbulletin->$options[option] have to equal to be true and false in a boolean mode?

Marco van Herwaarden
06-18-2006, 04:47 PM
You could easily change it to "== true" or "== false".

In most cases PHP will consider 0 to be false, and 1 to be true.

Adrian Schneider
06-18-2006, 06:19 PM
Better yet, just do this:
// true
if ($var)
{

}

// false
if (!$var)
{

}Make sure you quote 'option' otherwise if it is a defined constant, you will run into some problems. I also suggest using 'yesno' for the eval code for the option.

King Kovifor
06-20-2006, 12:16 AM
Better yet, just do this:
// true
if ($var)
{

}

// false
if (!$var)
{

}Make sure you quote 'option' otherwise if it is a defined constant, you will run into some problems. I also suggest using 'yesno' for the eval code for the option.

So I could do this:


if (THIS_SCRIPT == "index")
{
global $globaltemplates;
$option = $vbulletin->$option['option'];

if ($option)
{
$globaltemplates = array_merge($globaltemplates, array('template'));
}
if (!$option)
{
$globaltemplates = array_merge($globaltemplates, array('second_template'));
}
}

Adrian Schneider
06-20-2006, 12:48 AM
Close.

$option = $vbulletin->$option['option']; should be $option = $vbulletin->options['option'];where 'option' is the varname of your option.

The example I showed you if ($var)
{

}
if (!$var)
{

} can be achieved like this as well: if ($var)
{

}
else
{

}

King Kovifor
06-21-2006, 04:31 PM
Now it doesn't seem to be calling the template...

if (THIS_SCRIPT == "index")
{
global $globaltemplates;
$option = $vbulletin->$options['wp_style'];

if ($option)
{
$globaltemplates = array_merge($globaltemplates, array('forumhome_wp_kk'));
}
if (!$option)
{
$globaltemplates = array_merge($globaltemplates, array('forumhome_wp_dp'));
}
}

that's may actual code.