From m204wiki
Jump to navigation Jump to search

Find maximum value in array

Note: Many $functions have been deprecated in favor of Object Oriented methods. There is no direct OO equivalent for the $Arr_Max function because the OO methods emphasize the use of Collections over the use of arrays.

$Arr_Max can be used to find the maximum value in an array.


%result = $Arr_Max (array, maxnum)

%result A numeric variable that is set to the array element number that contains the indicated maximum value, or it is set to a -1 if the array or maxnum is invalid.
array An array of string, float, or fixed values. This array must be a single dimensional array and must not be an array in an image.
maxnum The highest array element number to check. This argument can be used to limit the search to the first n elements in an array, where n is a positive integer.

Usage notes

  • If the maximum value occurs in multiple array elements, $Arr_Max always returns the lowest array element number containing that value.


In the following example

%FXARRAY IS FIXED ARRAY(5) %FXARRAY(1) = 81 %FXARRAY(2) = 49 %FXARRAY(3) = 121 %FXARRAY(4) = 25 %NUM = $Arr_Max(%FXARRAY)

%NUM is set to 3.

In the following example


%NUM is set to 2.

Products authorizing $Arr_Max