Given this:
$ids = '';
I just realized that this:
$single = $ids == FALSE || is_array($ids)? FALSE : TRUE;
var_dump($single);
and this:
if ($ids == FALSE)
{
$single = TRUE;
}
else
{
if (is_array($ids))
{
$single = FALSE;
}
else
{
$single = TRUE;
}
}
var_dump($single);
Display different results (false and true respectively). However, This only happens when the variable is:
$ids = '';
or
$ids;
If $ids is an array, an integer, or a string it works fine. Does anybody know why? Thanks in advance!
By the way, I have just realized that if you type $ids === FALSE in the first conditional stament (the single line one) it will work fine. But I still don't understand the 'logic' behind this.
You forgot parentheses:
$single = (($ids == FALSE) || (is_array($ids)? FALSE : TRUE));
var_dump($single);
// Output: true
Without them, precedence gives you a result different from that which you were expecting:
<?php
$id = '';
$single = $ids == FALSE || is_array($ids)? FALSE : TRUE;
// ( ( ) )
// FALSE FALSE
var_dump($single); // False
$single = (($ids == FALSE) || (is_array($ids)? FALSE : TRUE));
// TRUE || FALSE
var_dump($single); // True
?>
Note that '' == FALSE
is true
; I'm not sure whether you realised that.
I could be wrong but It may be because you are returning a Boolean Equivlenant (1 / 0) or a True and False String. If you want Absolute equality try using 3 equals symbols.
The order of operations is different in the two examples. The first one is parsed as:
$single = ( $ids == FALSE || is_array($ids) ) ? FALSE : TRUE;
The second one is equal to:
$single = ( $ids == FALSE ) || ( is_array($ids)? FALSE : TRUE );