The project I have is a reimbursement of materials in a game. The materials come in various packages listed in the array below. Part of my code gives me the total number of units I need to reimburse, and I have to use the "packages" from the array below.
This is the multi dimensional array. The $item['ore'][100] array indicates that the item listed gives 100 units when used and stacks to only 100 (key => stacksize). Likewise for $item['ore'][500] gives 500 units when used and only stacks to 100:
$item = array(
'ore' => array(
100 => array(
'name' => "Item 1",
'stacksize' => 100,
),
500 => array(
'name' => "Item 2",
'stacksize' => 100,
),
1000 => array(
'name' => "Item 3",
'stacksize' => 100,
),
),
So, 1x Item 1 gives 100 units, 1x Item 2 gives 500 units and 1x Item 3 gives 1000 units. My $totalOre variable from part of my code dictates that I have 15,825 units to reimburse total (as an example). Obviously I'll have some extra that will be reimbursed as I don't have an item that gives smaller than 100 units (not a big deal if the user gets a bit more in this case).
So I need a code snippet to tell me that I need to reimburse 15x Item 3, 1x Item 2 and 4x Item 1 for a total of 15,900 units.
Additionally, if I have say....$totalOre = 219,427, I need my code to dictate that I send 100x Item 3, then 100x Item 3, then 19x Item 3, then 1x Item 2 for a total of 219,500 units, because of the 'stacksize' limitation of 100 (I can't send a user more than 100x of these items or they won't get them).
I assume some sort of loop would be needed in addition the Modulus (%) operator. I tried
$reimburseOre = 0;
$reimburseOre = $reimburseOre % $items['ore'][1000];
and came up with 0. Any assistance you can provide would be greatly appreciated, even just a hand in the right direction.
Thank you.
EDIT: Tried adding a 'Qty' key to my array (set to 1000) and then the following snippet of code and the result was -523 (not correct at all):
$oreReimbursement = 0;
if ($totalOre % $items['ore'][1000]['Qty'] != 0) {
$oreReimbursement -= $totalOre % $items['ore'][1000]['Qty'];
}
echo $oreReimbursement; ?>