I am making a game in php as a personal project.
I can make items out of items that I have, the items I have are stored in an array called $user
For now I am displaying how many of each item I can make by doing the following (let us say that to make a spade you need 1 wood and 1 metal and 1 energy)
$amount = min($user['wood'], $user['metal'], $user['energy']);
// USER HAS ITEMS TO MAKE SPADE
if ($amount) {
echo '<form class="spacerTop" action="#" method="post">
<input type="hidden" name="itemPlus" value="spade" />
<select name="amount">';
$i = 1;
while ($i <= $amount) {
echo '<option value"' . $i . '">' . $i . '</option>';
++$i;
}
echo '</select>
<input type="submit" value="Make Spades" />
</form>';
}
Doing the above will only show the option to make a spade if the user has the minimum amount of items to make a spade. It will also show in a form select how many spades they can make in total using the min value from php.
What I cannot work out is say if it costs 2 energy, 10 wood and 5 metal? How can I get the same functionality as above even if the items it costs to make an item differs?
Try this
This will give you the maximum amount of “stuff” given the requirements. A special case is where all divisors are 1 (then you don’t have to call
floorto round down the number).