Bug #73427 [Opn->Fbk]: Unintended behaviour of intersection functions

From: Date: Mon, 21 May 2018 06:46:03 +0000
Subject: Bug #73427 [Opn->Fbk]: Unintended behaviour of intersection functions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215315@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73427&edit=1 ID: 73427 Updated by: requinix@php.net Reported by: turabgarip at gmail dot com Summary: Unintended behaviour of intersection functions -Status: Open +Status: Feedback Type: Bug Package: Arrays related Operating System: Windows PHP Version: 5.6.27 Block user comment: N Private report: N New Comment: I don't see the "compare from the first three colors" behavior. Where/how are you seeing that? And I assume this also applies to PHP 7.1 and 7.2? Previous Comments: ------------------------------------------------------------------------ [2018-05-21 06:24:56] turabgarip at gmail dot com Wow, it's been years and no one actually took a glance on it? :) ------------------------------------------------------------------------ [2016-10-31 08:14:30] turabgarip at gmail dot com Description: ------------ Intersection functions intend to compute the intersection of two or more arrays; but they try to compare the elements of the individual array itself. This is contradictory to the logic of intersection. Thus it makes the intersection functions considerably slow. In the test script, there are two arrays. Intersection will start to compare from the first three colors like; "blue" to "green", "black" to "blue"; that are, the elements of the first array only; which are actually very unnecessary to compare. Because the actual intention is to compute the intersection of the two arrays; not the intersection of the elements of the array itself. However an array can contain only one identical element at once anyway, so it's useless and resource consuming to check the array's own elements against each other. Test script: --------------- $arr1 = array('green', 'blue', 'black'); $arr2 = array('yellow', 'red', 'cyan'); array_intersect($arr1, $arr2); Expected result: ---------------- Intersection function should compare the elements of the given arrays crosswise. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=73427&edit=1

« previous php.bugs (#215315) next »