Page 1 of 1

max value from a nested array

Posted: Mon Sep 06, 2010 4:32 am
by rahulsonar
Hello All,

I have defined a function, can someone tell me if this is correct?

Code: Select all

function Max_value($arr)
{
	global $new;
	foreach($arr as $value)
	{
		if(is_array($value))
		{
			Max_value($value);
		}
		else
		{
			$new[] = $value;
		}
	}
	return max($new);
}
This works perfect.. but I dont know if I can use global variable now.

Thanks,

Re: max value from a nested array

Posted: Mon Sep 06, 2010 4:56 am
by arrielmabale
you dont need to use global, a good coding structure can spread a value around your site