Jump to content

Getting the max amount from foreach


ianp

Recommended Posts

I am an intern with a friend and he asked me to program a script where it gets the largest amount. I setup a function but am not sure how to go on from there, can anyone help me? By the way max_amt is suppose to be the max amount.

$day = array('0','-1','-2','-3','-4');
foreach($day as $night)
{
if ($night === end($day))
     {
	$end = '';
}else
{
	$end = ',';
}
	 include('../Connections/default.php');
	 $date_m = date('m', strtotime(''.$night.' days'));
	 $date_d = date('d', strtotime(''.$night.' days'));
	 $date_Y = date('Y', strtotime(''.$night.' days'));
	 mysql_select_db($database_default, $default);
         $query_uvs = "SELECT DISTINCT `ip` FROM `stats` WHERE `month` = '".$date_m."' AND `day` = '".$date_d."' AND `year` = '".$date_Y."'";
         $uvs = mysql_query($query_uvs, $default) or die(mysql_error());
     $total_uvs = mysql_num_rows($uvs);
echo  ''.$total_uvs.''.$end.'';
}
$max_amt = '1';

Link to comment
https://forums.phpfreaks.com/topic/264761-getting-the-max-amount-from-foreach/
Share on other sites

The script I programmed is suppose to echo 1,2,3,4,5. The problem is when I try max(vcount(array('0','-1','-2','-3','-4'))) it just display 1,2,3,4,5. (I tried doing a function with the same foreach method shown in my previous post.)

 

?

 

So... it's doing what you want, but that's not what it's supposed to do?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.