I’m getting data from a MySQL database and trying to check if the column has data in it or not. Here’s what one of the array elements looks like:
[2] => Array
(
[p_name] => This is text
)
Now I have the following statement:
if($products[2]['p_name'] == 0)
echo '$products[2][\'p_name\'] == 0';
The output is:
"$products[2]['p_name'] == 0"
Now, is it just me, or is that not make any sense whatsoever?
A textual string casted to a number is always 0:
(int) 'This is Text'is equal to 0.You could just use the
empty()function oris_numeric()and then your code:(which check if
$varis either""(an empty string),0(0 as an integer),0.0(0 as a float),"0"(0 as a string),NULL,FALSEorarray()).or