SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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,

    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

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It sounds like you want something like this:

    PHP Code:
    $levels = array(
      
    => 100,
      
    => 200,
      
    => 300,
      
    => 400
      
    => 500,
      
    => 600,
      
    => 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:

    Code:
    You have 610 experience which is level 6


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •