Monkuar Posted March 4, 2012 Share Posted March 4, 2012 if ($user['amount'] >= 15.00){ $user['max_stars'] = 3; } Ok and if ($user['amount'] >= 20.00){ $user['max_stars'] = 4; } How can I write a function that will loop through the 15,20,25,30,35, all the way up to 600$ or if the max_Stars get's up to 80? I really don't want to have 80 if functions in my code :\ Link to comment https://forums.phpfreaks.com/topic/258257-how-do-i-make-my-own-math-equation/ Share on other sites More sharing options...
requinix Posted March 4, 2012 Share Posted March 4, 2012 Is it consistently X/5? Hint: it's consistently X/5. define("AMOUNT_PER_STAR", 5); define("MAX_AMOUNT_FOR_STARS", 400); // you said 600, but $80*5=400 define("MIN_AMOUNT_FOR_STARS", 15); if ($user["amount"] >= MIN_AMOUNT_FOR_STARS) { $amount = min($user["amount"], MAX_AMOUNT_FOR_STARS); $user["max_stars"] = floor($amount / AMOUNT_PER_STAR); } Normally I don't litter my code with lots of constants but for some reason I felt like it this time. Link to comment https://forums.phpfreaks.com/topic/258257-how-do-i-make-my-own-math-equation/#findComment-1323832 Share on other sites More sharing options...
ignace Posted March 4, 2012 Share Posted March 4, 2012 Can you describe what you are trying to do? Why are you looping over 15 -> 600 and what do you mean by "all the way up to 600$ or if the max_Stars get's up to 80?" Link to comment https://forums.phpfreaks.com/topic/258257-how-do-i-make-my-own-math-equation/#findComment-1323840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.