Good day
I am trying to get a counter for my foreach loop on my arraylist.
This is what my code looks like at the moment
note : $count = -1; is set like that to start the counter on 0 to work with the arraylist which starts counting at 0
$AmountList = new ArrayList();
$count = -1 ;
foreach($Amounts as $item ) {
$count = $count+1;
print_r($count);
//Declare variables and do calculations on them
$ModelNo = $item['ModelNo'];
$ImageURL = $item['ImageURL'];
$Manufacturer = $item['Manufacturer'];
$Retail = $item['RetailPrice'];
$IncVat = $item['IncVat'];
//Build new array with calculated data
$AmountList->push(
new ArrayData(array(
'ModelNo' => $ModelNo,
'ImageURL' => $ImageURL,
'ItemAmount'=>$ItemAmount[$count],
'Manufacturer' => $Manufacturer,
'RetailPrice' => ($Retail)*($ItemAmount[$count]),
'IncVat' => ($Retail)*($AmountItems[$count])*(114)/(100),
'TotalAmount'=>$IncVat
))
);
return $AmountList;
}
If anyone can give me any ideas of what i could do better to get the counter to work
Thanks in advance