#3289 [Opn->Csd]: min() and max() have wierd problems when using a mixed int and string array.

From: Date: Mon, 30 Sep 2002 22:26:50 +0000
Subject: #3289 [Opn->Csd]: min() and max() have wierd problems when using a mixed int and string array.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-20803@lists.php.net to get a copy of this message
ID: 3289 Updated by: hholzgra@php.net Reported By: c.just@its.uq.edu.au -Status: Open +Status: Closed Bug Type: Misbehaving function Operating System: Linux and Win32 PHP Version: 3.0.14 New Comment: fixed in php4 Previous Comments: ------------------------------------------------------------------------ [2000-01-23 19:09:14] c.just@its.uq.edu.au I have found a very strange problem with the min() and max() functions. I just thought I'd check with the list first before I submitted it. It seems both functions have problems when there are a mix of strings and integers. Even thought the strings are actually numbers(no alpha chars) Max has a problem when there is a string first. I have tested this in PHP Linux 3.0.14 PHP Win32 3.0.13 PHP Win32 3.0.5 Try the code below out. <? echo "Array values<BR>"; $stats = array(40,10,120,100,380); for($i=0;$i<count($stats);$i++) echo "$i - ".$stats[$i]."<BR>"; echo "<HR>"; $stats = array(40,"10",120,100,"380"); $high = max($stats); $low = min($stats); echo "Array with Mixed String and Integers<BR>"; echo "Min - ".$low."<br>"; echo "Max - ".$high."<br><HR>"; $stats = array("40","10",120,100,"380"); $high = max($stats); $low = min($stats); echo "Array with Mixed String and Integers, With String as first element<BR>"; echo "Min - ".$low."<br>"; echo "Max - ".$high."<br><HR>"; $stats = array(40,10,120,100,380); $high = max($stats); $low = min($stats); echo "Array with Integers Only<BR>"; echo "Min - ".$low."<br>"; echo "Max - ".$high."<br><HR>"; $stats = array(40,"10",120,100,"380"); // CONVERT ALL VALUES TO INTEGERS for ($i=0;$i<count($stats);$i++) $stats[$i]=intval($stats[$i]); $high = max($stats); $low = min($stats); echo "Array with Mixed String and Integers converted to integers<BR>"; echo "Min - ".$low."<br>"; echo "Max - ".$high."<br><HR>"; ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=3289&edit=1

« previous php.bugs (#20803) next »