note 93614 added to language.operators.comparison
| From: | pinkgothic at gmail dot com | Date: | Fri, 18 Sep 2009 11:28:37 +0000 |
| Subject: | note 93614 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160824@lists.php.net to get a copy of this message | ||
"Array with fewer members is smaller, if key from operand 1 is not found in operand 2 then
arrays are uncomparable, otherwise - compare value by value (see following example)."
The example covers this behaviour, but it isn't immediately obvious, so:
If you're doing loose comparisons in PHP, note that they differ from checking each value
individually like $value1==$value2 by adding what amounts to an empty($value1)==empty($value2) check
into the mix. I found this out by investigating some (to me) bizarre behaviour.
[Note that the example contains no ==, just > and <. It's its absence that perceivedly
'causes empty() to fire'.]
I was also pleasantly surprised to see PHP recurse. Also clear if you keep in mind that the example
implies another function call to itself with > and < if both operands are arrays, but IMO
definitely worth stating.
It might also be worth noting that the order of array keys doesn't matter, even if a foreach()
would see a 'different' array. Again, covered by the example, but might be worth
stressing.
----
Server IP: 212.124.37.9
Probable Submitter: 80.153.202.193
----
Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php
Edit -- https://master.php.net/note/edit/93614
Del: integrated -- https://master.php.net/note/delete/93614/integrated
Del: useless -- https://master.php.net/note/delete/93614/useless
Del: bad code -- https://master.php.net/note/delete/93614/bad+code
Del: spam -- https://master.php.net/note/delete/93614/spam
Del: non-english -- https://master.php.net/note/delete/93614/non-english
Del: in docs -- https://master.php.net/note/delete/93614/in+docs
Del: other reasons-- https://master.php.net/note/delete/93614
Reject -- https://master.php.net/note/reject/93614
Search -- https://master.php.net/manage/user-notes.php