note 34233 added to function.min

From: Date: Sat, 19 Jul 2003 01:28:09 +0000
Subject: note 34233 added to function.min
Groups: php.notes 
Request: Send a blank email to php-notes+get-52370@lists.php.net to get a copy of this message
Further modifications to the minnum function above.. This is for a project where I had to grab an entire column out of a database consisting of values that might be string, might be string representations of numbers (floating point or integer) or might be NULL, and find the minimum NUMERIC value: function minnum($numarray){ //dont use min(), it contains a bug! $min=0; if ( ! is_array($numarray) ) $numarray = func_get_args(); if(is_array($numarray)==true){ $min=max($numarray); for($z=0;$z<count($numarray);$z++){ $curval=floatval($numarray[$z]); if(($curval != 0) && ($curval < $min)){ $min=$curval; } } } return $min; } Gets the floating point value of each entry and uses this to check whether it's actually a number before checking whether it's the minimum or not. Also contains modifications noted above to use it as a drop in replacement for min - ie multiple values passed. ---- Manual Page -- http://www.php.net/manual/en/function.min.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34233 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34233&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34233&report=yes

« previous php.notes (#52370) next »