if(0 == ('Pictures'))
{
echo 'true';
}
why it's giving me 'true' ?
if(0 == ('Pictures'))
{
echo 'true';
}
why it's giving me 'true' ?
Your string will be evaluated as an Integer, so becomes 0, use this : 0 === 'Pictures'
that verifies identity (same value and same type)
Use:
if (0 === 'Pictures')
{
echo 'true';
}
The ===
is strict type operator, it not only checks the value but the type as well.
Quick Test:
if(0 == 'Pictures')
{
echo 'true';
}
else
{
echo 'false';
}
outputs true
but:
if(0 === 'Pictures')
{
echo 'true';
}
else
{
echo 'false';
}
outputs false
Check PHP type comparison tables to understand how comparison operators behave in PHP.
In your case, 'Pictures' becomes "0" and therefore 0 = 0.
Let's check following example:
echo (int)'Pictures'; // 0 => 'Picture' as int
echo 0 == 'Pictures'; // 1 => true, 0 = 0