php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70850 error in summary of array comparison
Submitted: 2015-11-03 21:53 UTC Modified: 2017-01-28 13:53 UTC
From: JQKP at example dot com Assigned:
Status: Verified Package: Arrays related
PHP Version: 5.6.15 OS: MS Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
34 - 26 = ?
Subscribe to this entry?

 
 [2015-11-03 21:53 UTC] 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".


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-03 22:57 UTC] 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
 [2017-01-28 13:53 UTC] cmb@php.net
-Status: Open +Status: Verified -Package: Documentation problem +Package: Arrays related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 17:01:29 2024 UTC