(php) if condition not working
I am going crazy here. The following simple if-condition does not produce the right output.
$xxx = 1;
if($xxx == 1)
define('DEBUG', true);
else
define('DEBUG', false);
var_dump($xxx)开发者_JAVA技巧;
var_dump(DEBUG);
die();
Output:
int(1)
bool(false)
I see absolutely no reason why the DEBUG constant is not being set to true. PHP's type juggling should allow this if-statement. And even if I put an intval in front of the variable, it still produces false as output.
Edit 2: I copied the exact code from above into a new file and it produces the expected output. So I don't know what is going on...
var_dump($vbulletin->userinfo['userid']);
Output :
string(1)
Your string length is one, and it seems to be empty (a space ?).
$vbulletin = new stdClass();
$vbulletin->userinfo = array('userid' => 1);
if(1 == $vbulletin->userinfo['userid'])
define('DEBUG', true);
else
define('DEBUG', false);
var_dump(DEBUG);
echo "\n";
var_dump($vbulletin->userinfo['userid']);
There isn't anything wrong with your code. Running the above code gives me
bool(true) int(1)
I suspect your $vbulletin->userinfo['userid']
variable has a different value to what you think it has
EDIT
When I change it to
$vbulletin->userinfo = array('userid' => '1');
I get string(1) "1"
. You're string appears to be empty, and that's the reason it's failing.
精彩评论