php string comparison unexpected type juggling
<p>I encountered a strange and unexpected behavior in PHP while comparing some string values. The first two statements below return true when I would expect them to return false. The last statement returns false as expected. I'm aware of PHP's <a href="http://php.net/manual/en/language.types.type-juggling.php" rel="nofollow">Type Juggling</a>, but what I understand from the docs is that type juggling happens when you are comparing two different data types like a string and an integer. In the examples below though both literals are strings. Does this mean that when you are doing string comparison in PHP it inspects both strings to see if they look like integers and if so type casts the both of them to integers and then compares those integer values. So my question is under what conditions does this behavior happen, how exactly does string comparison work in PHP? </p>

<pre><code>var_dump("10" == "10.0000");
var_dump("10" == "+10.");
var_dump("10" == "10 ");

#output
bool(true)
bool(true)
bool(false)
</code></pre>

<p><strong>Updates</strong></p>

<p>So baba's answer below <a href="http://www.php.net/manual/en/language.operators.comparison.php" rel="nofollow">comparison involves numerical strings</a> really helped in getting me to understand what's going on. The function <a href="http://php.net/manual/en/function.is-numeric.php" rel="nofollow">is_numeric</a> will return to you whether or not a string is considered to be a numeric string. interestingly <code>"10 "</code> is not considered a numeric string but <code>" 10"</code> is. I dug around the PHP source code and I believe the <a href="https://github.com/php/php-src/blob/master/Zend/zend_operators.h#L108" rel="nofollow">implementation of is_numeric</a> is in the is_numeric_string_ex function. From that one can tell exactly when PHP will treat a string as a numeric string.</p>
