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

From: Date: Tue, 29 Dec 2009 16:44:37 +0000
Subject: #50607 [NEW]: max() should say more about multi-dimensional arrays
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3584@lists.php.net to get a copy of this message
From: thiago@php.net Operating system: PHP version: Irrelevant PHP Bug Type: Documentation problem Bug description: max() should say more about multi-dimensional arrays 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 bug report at http://bugs.php.net/?id=50607&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50607&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50607&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50607&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=50607&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50607&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=50607&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=50607&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=50607&r=needscript Try newer version: http://bugs.php.net/fix.php?id=50607&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=50607&r=support Expected behavior: http://bugs.php.net/fix.php?id=50607&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=50607&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=50607&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=50607&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50607&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=50607&r=dst IIS Stability: http://bugs.php.net/fix.php?id=50607&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=50607&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=50607&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=50607&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=50607&r=mysqlcfg

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