PHP Array Strange problem
As follows:
PHP Code
$arr 1 is the data extracted from the database, Print_r out as follows: Array ( [0] = 30544 [1] = 30544 [2] = = 30532 [3] = 30550 [4] = 30544 [5] = 30544 [6] = 30532 [7] = 30532 [8] = 30532 [9] = = 30550 [ten] = 30544
[11] = 30544 [16] = 30544 [] = 30544 [+] = 30544 [[] [] = 30544] =& Gt 30532 [] = 30532 [2] = 30532 [n] = 30532) $arr = Array (' 1 ', ' 2 ', ' 4 ', ' 5 ');//I use the same function Max () The maximum value, the result is as follows://ARR1 result, will be error, but can fetch data 30550A PHP Error was EncounteredSeverity:WarningMessage:max () [Function.max]: When Only one parameter are given, it must be a arrayFilename:test.phpLine number:104//arr2 normal, output 5
Above, the error is why ah, how to solve AH. Thank you.
------Solution--------------------
Max () [Function.max]: When only one parameter are given, it must be an array
When Max is a parameter, it must be a number of arrays.
PHP Code
Logminmath function php Manual--------------------------------------------max (PHP 4, PHP 5) max-Find the maximum description mixed max (number $arg 1 , number $arg 2) mixed max (array s [, array $ ...] Max () returns the value with the largest number in the parameter. If there is only one parameter and an array, Max () returns the largest value in the array. If the first argument is an integer, a string, or a floating-point number, then at least two parameters are required and Max () returns the largest of these values. You can compare an unlimited number of values. Note:php will treat a non-numeric string as 0, but if this is the maximum value, it will still return a string. If more than one parameter evaluates to 0 and is the maximum, max () returns 0 of the value, and if there is no value of 0 in the argument, the string that is the largest in alphabetical order is returned. Examples of Example #1 using Max ()
See min () and count (). User contributed notessun at drupal dot org 03-aug-2011 11:25 Note this Max () throws a warning if the array is empty:
So make sure your data isn ' t empty. php at rijkvanwel Dot nl 12-apr-2011 02:08 to get the largest key in an array:
' First ', 1=> ' second ',/* ... */"nth"); $max _key = max (Array_keys ($array)); 99?> Alex Stanhope 28-oct-2010 03:00 If you want to test whether x lies within both bounds:
= Min ($y 1, $y 2)) && ($x <= Max ($y 1, $y 2))); }//called By:class::isinrange (10,12,2); or $this->isinrange (10,12,2); or (drop static) Isinrange (10,12,2); Simple test function:static function Unit_isinrange () {$output = array (); $inputlist [] = Array (ten, 2, true); $inputlist [] = Array (2, false); $inputlist [] = Array (2,-2, 2, true); $inputlist [] = Array (2,-8,-2, false); foreach ($inputlist as $input) {$output [] = array (' input ' = = Array ($input [0], $input [1], $ INPUT[2]), ' Output ' = Self::isinrange ($input [0], $input [1], $input [2]), ' expected ' = $input [3],); } return ($output); }?> dan at coders Dot co dot nz 22-may-2010 11:29 max () on undefined parameters does isn't assume the value is zero, it Ignores it.
-2); If $dimensions [' right '] is never set,//We may expect it to is treated as zero, but print max ($dimensions [' left '], $d Imensions[' right ']); Returns-2, not zero print max (0+ $dimensions ["left"], 0+ $dimensions [' right ']);?> would is a work-around, but it ' s probably tidier to ensure your values is set correctly first. (on PHP 5.2.11 anyway) Alex Rath 10-apr-2010 11:27 Notice that whenever there are a number in front of the String, it'll be used for Comparison.
But just if it was in front of the String
Grillen at abendstille dot @ 02-apr-2010 03:55 Max only accepts not empty arrays. If you work a lot with numerical arrays and with Max, this function may be come in handy:
Artem dot yagutyan at gmail dot com 27-mar-2010 03:28 this was good example:for max to min
$val) {if ($val = = max ($array)) return $key; }} $array = Array (ten, 2, 5, 7, 4,15,32,8,41,25); $array _count=count ($array); for ($i =1; $i <= $array _count; $i + +) {$max _val[$i]=max_key ($array); $view = $array [$max _val[$i]; Unset ($array [$max _val[$i]]); Print $view. "
"; }/* OUTPUT41//Max3225151087542//min*/?> Marcini 11-may-2009 07:34 Note that Max () can compare dates, so if you WR Ite something like this:
You'll get:2009-03-15. Ries at vantwisk Dot nl 09-nov-2008 06:36 I had several occasions that using Max are a lot slower then using a if/then/else Construct. Be sure to check this in your routines! Ries Marcus Zacco 29-sep-2008 09:47 This code loops through seven arrays and finds the highest average value within those Arrays-and changes the font color for it. Great for highlighting. The biggest take-away is this the row if ($average [$i] = = max ($average)) The Number_format just rounds the numbers to 0 Dec iMAL points.
"; } else {echo "Value". $num. ":". Number_format ($average [$i],0, '. ', '). "
"; }}?> # # OUTPUT value 1:52% value 2:58% value 3:56% value 4:73% value 5:77% <-this are highlighted in Red Value 6:71% value 7:75% harmor 21-feb-2008 09:56 A-to bound a integer between the values is:
Which is the same as:
$max) {$tmp = $max;} $y = $tmp;?> So if wanted to bound a integer between 1 and for Example:input:
'; $x = 1; echo Bound ($x, 1, 12). '
'; $x = 6; echo Bound ($x, 1, 12). '
'; $x = 12; echo Bound ($x, 1, 12). '
'; $x = 13; echo Bound ($x, 1, 12). '
';?> output:1 1 6 michaelangel0 at mail.com 04-jul-2007 03:00 Matlab Users and others may feel lonely without t He double argument output from Min and Max functions. To has the INDEX of the highest value in an array, as well as the value itself, use the following, or a derivative:
$maxvalue, "i" = = $maxindex); }?> jeremi23 at gmail dot com 14-jun-2007 03:09 max in a array with key/values
5, 2=> 3); echo Max ($tmp);?> This return 5, so that the max is do on the values. johnmott59 at hotmail dot com 17-may-2007 12:35 to find the maximum value from a set of 1-dimensional arrays, does this:
The Inner Max () functions operate on the arrays, the outer max compares the numeric results of the inner ones. Johnphayes at gmail dot com 02-may-2006 09:27 regarding boolean parameters in Min () and Max ():(a) If any of your parameter S is Boolean, Max and Min would cast the rest of them to the comparison. (b) True > False (c) However, Max and Min would return the actual parameter value that wins the comparison (not the cast) . Here's some test cases to illustrate:1. Max (true,100) =true2. Max (true,0) =true3. Max (100,true) =1004. Max (false,100) =1005. Max (100,false) =1006. Min (true,100) =true7. Min (true,0) =08. Min (100,true) =1009. Min (false,100) =false10. Min (100,false) =false11. Min (true,false) =false12. Max (true,false) =true--------------------------------------------logminmath function php Manual