Bug #54980 [Opn->Nab]: array_multisort uses second array to sort

From: Date: Fri, 08 May 2015 21:56:26 +0000
Subject: Bug #54980 [Opn->Nab]: array_multisort uses second array to sort
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192593@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=54980&edit=1 ID: 54980 Updated by: cmb@php.net Reported by: chx1975 at gmail dot com Summary: array_multisort uses second array to sort -Status: Open +Status: Not a bug Type: Bug Package: Arrays related Operating System: Irrelevant PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: | I thought array_multisort sorts the first array and orders the | consequent arrays accordingly. That's only half the story. If there are identical values in the first array, the respective elements of the second array are compared to decide the order. See example #1, where this is documented. Previous Comments: ------------------------------------------------------------------------ [2011-06-03 09:30:32] chx1975 at gmail dot com Description: ------------ I thought array_multisort sorts the first array and orders the consequent arrays accordingly. Changing $sort['C'] to 3 indeed makes the error message go away so we think the error is only triggered if the sort does not happen in the first array. This is related to http://bugs.php.net/bug.php?id=54259 but I have simplified Brad's script as much as I can -- and he reported as a feature request. I think this is a bug. At least a documentation bug. Test script: --------------- $sort['A'] = 2; $sort['B'] = 1; $sort['C'] = 1; $menu['A'] = 0; $menu['B'] = (object) array(0); $menu['C'] = 0; array_multisort($sort, SORT_NUMERIC, $menu); Expected result: ---------------- No error message shown Actual result: -------------- PHP Notice: Object of class stdClass could not be converted to int in /tmp/chx_array_multisort.txt on line 11 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=54980&edit=1

« previous php.bugs (#192593) next »