Using php to get an array and count the number

Hi there all,

I am having a problem with a level system ive been given in flash and i had to take it and turn it into php code,

How i did this manually but not sure what i did wrong this is my php code,


$mexp=array(0,100,210,330);
  for($i=0; $i<=$mexp; $i++)
  {
	if ($c>=$mexp[$i] && $c<$mexp[$i]+1)
	{
	   echo "".$i."";
	}
	else
	{
		return $i;	
	}
  }

How can i fix it? is it possible to calculate the number as the user’s exp is 600 and if its between 600 and 750 then its x level which is about level 5 or 6 using php can this be done if so how can i go about this?

Thanks,William

It sounds like you want something like this:

$levels = array(
  1 => 100,
  2 => 200,
  3 => 300,
  4 => 400, 
  5 => 500,
  6 => 600,
  7 => 750
);

$player_level = 1;
$player_experience = 610;

foreach ($levels as $level => $exp_required) {
  if ($player_experience >= $exp_required) {
    $player_level = $level;
  }
}

echo "You have " . $player_experience . " experience which is level " . $player_level;

Output:

You have 610 experience which is level 6