Doc #70850 [Opn->Ver]: error in summary of array comparison

From: Date: Sat, 28 Jan 2017 13:53:02 +0000
Subject: Doc #70850 [Opn->Ver]: error in summary of array comparison
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-14383@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70850&edit=1 ID: 70850 Updated by: cmb@php.net Reported by: JQKP at example dot com Summary: error in summary of array comparison -Status: Open +Status: Verified Type: Documentation Problem -Package: Documentation problem +Package: Arrays related Operating System: MS Windows PHP Version: 5.6.15 Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2015-11-03 22:57:30] requinix@php.net It's not so much wrong as it is unclear how the comparison works. It doesn't check all the keys in operand 1 against those in operand 2 and *then* do the value comparison. Rather, as it loops through operand 1 it first checks that operand 2 has the key before trying to compare their two values. https://3v4l.org/1QXcc ------------------------------------------------------------------------ [2015-11-03 21:53:34] JQKP at example dot com Description: ------------ --- From manual page: http://www.php.net/language.operators.comparison --- > 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 This is not true. See my test script below. (However, the "Example #2 Transcription of standard array comparison" on the manual page does seem to be true.) Test script: --------------- C:\Users\Michael>php <?php $a=[1=>1,2=>3]; $b=[1=>2,6=>7]; print $a<$b; # This prints 1 because it compares the first keys. # However, according to the manual, as quoted above, # it should print '' because "key from operand 1 # [namely 2] is not found in operand 2". ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70850&edit=1

« previous php.doc.bugs (#14383) next »