Author Message

John Richardson

uk
15 posts

Location: United Kingdom
Occupation:
Age:
#14   02-02-2010 10:13 GMT      
Php max function is a quick and dirty way to extract the highest value but as I found out recently you can come unstuck. I needed some thing that could evaluate strings such as 3aA, 2b3, 3a1 the following bubblesort routine to arrange in order and array_pop to get the last value from the sorted array did the trick.

function maxjr($sort_array,$reverse){
for ($i = 0; $i < sizeof($sort_array); $i++){ 
	for ($j = $i + 1; $j < sizeof($sort_array); $j++){ 
		if($reverse){ 
			if ($sort_array[$i] < $sort_array[$j]){ 
			$tmp = $sort_array[$i]; 
			$sort_array[$i] = $sort_array[$j]; 
			$sort_array[$j] = $tmp; 
		} 
	} else { 
	if ($sort_array[$i] > $sort_array[$j]){ 
	$tmp = $sort_array[$i]; 
	$sort_array[$i] = $sort_array[$j]; 
	$sort_array[$j] = $tmp; 
		} 
	} 
} 
} 
$max_val = array_pop($sort_array);
return $max_val;  
} 

Usage:
$maxvalue = maxjr($input_array); 
This website is ACAP-enabled   The International Webmasters Association  Web Design Company |  UK Web Designers & Developers Office of Government Commerce Science City York Hexamail.com Eclipse.org Valid XHTML 1.0 Transitional The HTML Writers Guild

Copyright © 2010 Innovative Technology
( The business 4 Innovative Technology )
Page created in 0.092 seconds