KI114 Posted January 25, 2008 Share Posted January 25, 2008 Why won't this work?!?!? function findlevel($exp){ $found = false; $arrayno = 0; $levels = array(250,500,750,1000,1500,2000,2500,3000,4000,5000,6000,7000,9000); while($found == false){ if($arrayno == 14){ $level = 13; }else{ if($exp > $levels["$arrayno"]){ $arrayno += 1; }else{ $level = $arrayno += 1; return $level; $found = true; } } } } Quote Link to comment https://forums.phpfreaks.com/topic/87828-solved-help/ Share on other sites More sharing options...
resago Posted January 25, 2008 Share Posted January 25, 2008 what is it suppose to do? What does it currently do? Quote Link to comment https://forums.phpfreaks.com/topic/87828-solved-help/#findComment-449287 Share on other sites More sharing options...
KI114 Posted January 25, 2008 Author Share Posted January 25, 2008 It's suppose to find out what level a player is on my game from their Experience ($exp) and then put it in a variable which I can use. At the moment it doesn't do anything :-\ Quote Link to comment https://forums.phpfreaks.com/topic/87828-solved-help/#findComment-449337 Share on other sites More sharing options...
resago Posted January 25, 2008 Share Posted January 25, 2008 could you repost your code with indents? Quote Link to comment https://forums.phpfreaks.com/topic/87828-solved-help/#findComment-449341 Share on other sites More sharing options...
KI114 Posted January 25, 2008 Author Share Posted January 25, 2008 function findlevel($exp){ $found = false; $arrayno = 0; $levels = array(250,500,750,1000,1500,2000,2500,3000,4000,5000,6000,7000,9000); while($found == false){ if($arrayno == 14){ $level = 13; }else{ if($exp > $levels[$arrayno]){ $arrayno += 1; }else{ $level = $arrayno += 1; return $level; $found = true; } } } } Quote Link to comment https://forums.phpfreaks.com/topic/87828-solved-help/#findComment-449354 Share on other sites More sharing options...
kenrbnsn Posted January 26, 2008 Share Posted January 26, 2008 I just tried your code and it seems to work for me. How are you using it? Ken Quote Link to comment https://forums.phpfreaks.com/topic/87828-solved-help/#findComment-449382 Share on other sites More sharing options...
KI114 Posted January 26, 2008 Author Share Posted January 26, 2008 At the moment I'm just using it like this <? function findlevel($exp){ $found = false; $arrayno = 0; $levels = array(250,500,750,1000,1500,2000,2500,3000,4000,5000,6000,7000,9000); while($found == false){ if($arrayno == 14){ $level = 13; }else{ if($exp > $levels[$arrayno]){ $arrayno += 1; }else{ $level = $arrayno += 1; return $level; $found = true; } } } } findlevel(1234); echo($level); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87828-solved-help/#findComment-449776 Share on other sites More sharing options...
kenrbnsn Posted January 26, 2008 Share Posted January 26, 2008 You need to assign the value returned by the function to a variable. Do this: <?php $level = findlevel(1234); echo $level; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/87828-solved-help/#findComment-449781 Share on other sites More sharing options...
laffin Posted January 26, 2008 Share Posted January 26, 2008 <? function findlevel($exp){ $found = false; $arrayno = 0; $levels = array(0,250,500,750,1000,1500,2000,2500,3000,4000,5000,6000,7000,9000); $levelc = count($levels); $level=0; while($level < $levelc && $levels[$level]<$exp) $level++; return $level; } $level=findlevel(1234); echo($level); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87828-solved-help/#findComment-449785 Share on other sites More sharing options...
KI114 Posted January 26, 2008 Author Share Posted January 26, 2008 Thank You!!! I never have used function. But it works great now! Thanks for help. Quote Link to comment https://forums.phpfreaks.com/topic/87828-solved-help/#findComment-449788 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.