#50607 [Opn->Csd]: max() should say more about multi-dimensional arrays

From: Date: Tue, 12 Jan 2010 11:06:07 +0000
Subject: #50607 [Opn->Csd]: max() should say more about multi-dimensional arrays
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3678@lists.php.net to get a copy of this message
ID: 50607 Updated by: degeberg@php.net Reported By: thiago@php.net -Status: Open +Status: Closed Bug Type: Documentation problem PHP Version: Irrelevant New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2010-01-12 11:04:06] svn@php.net Automatic comment from SVN on behalf of degeberg Revision: http://svn.php.net/viewvc/?view=revision&revision=293443 Log: Clarified comparison rules for max(). Closes PHP bug #50607 (max() should say more about multi-dimensional arrays) ------------------------------------------------------------------------ [2009-12-29 16:44:37] thiago@php.net Description: ------------ I'm removing a few notes from max() docs because I think some of it's content should be added to docs. Note #87547 from sumeruter+php add an at gmail dot com: "An interesting feature not mentioned is that if a recursive array is passed to max, max will return the sub-array containing the highest value. Example: <?php $depth3=array( array(array(1,6,3),array(7,2,5),array(9,3,0)), array(array(2,1,8),array(4,4,5),array( 99 ,6,7)), array(array(0,3,2),array(5,91,11),array(42,25,12))); $depth2=max($depth3); // = array(array(2,1,8),array(4,4,5),array( 99 ,6,7)) $depth1=max($depth2); // = array( 99 ,6,7) $depth0=max($depth1); // = 99 echo max(max(max($depth3))); // echo 99; ?>" Note #92073 from soapergem at gmail dot com: A quick addendum to the comment left by "sumeruter": the recursive property will only work if all the sub-arrays are exactly the same length. Otherwise it will just return the longest array every time. Note #95367 from vendelin8 at gmail dot com: I disagree with sumeruter that in case of a recursive array php returnes the sub-array containing the highest value recursively. It checks the first value. Eg. $array = array(array(2, 3, 4), array(1, 4, 5)); print_r(max($array)); result: Array ( [0] => 2 [1] => 3 [2] => 4 ) In sumeruter's example the maximal value was always in the array that has the highest first value as well. Expected result: ---------------- This is the example of information I think should be added in docs: When a multi-dimensional array is given, this function returns the sub- array with highest first value. In order to copare multi-dimensional arrays, they should have the exact same size. (I could not test to ensure this behavior tho) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50607&edit=1

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