Why does PHP consider 0 to be equal to a string? -
i have following piece of code:
$item['price'] = 0; /*code item information goes in here*/ if($item['price'] == 'e') { $item['price'] = -1; }
it intended initialize item price 0 , information it. if price informed 'e' means exchange instead of sell, indicated negative value because stored in database requires numeric value.
there possibility leave price 0, either because item bonus or because price set in later moment.
but, when price not set, leaves initial value of 0, if loop indicated above evaluates true , price set -1. is, considers 0 equal 'e'.
how can explained?
edit: when price provided 0 (after initialization), behavior erratic: if evaluates true, evaluates false.
you doing ==
sorts out types you.
0
int, in case going cast 'e'
int. not parseable one, , become 0
. string '0e'
become 0
, , match!
use ===
Comments
Post a Comment