<?php
$fences_arr=[8,12,13,36,100,120];
function QuantityCarton($fences){
$result = $fences/12;
if($result>=0){
if(is_float($result)){
return ceil($result);
}else{
return $result;
}
}
}
for($i=0;$i<count($fences_arr);$i++){
echo "Quantity Cartons for ".$fences_arr[$i]." is ".QuantityCarton($fences_arr[$i])."<br />";
}
?>
Jeśli te dane pobierasz z bazy to zamień index'y asocjacyjne na te ponumerowane od zera do x, czyli skorzystaj z jednej z tych dwóch instrukcji, może można z jakichś innych, nie wiem:
$row = $result->fetch_array(MYSQLI_NUM);
// or
$result = $sth->fetchAll(PDO::FETCH_COLUMN, 0);
http://php.net/manual/en/mysqli-result.fetch-array.php
http://php.net/manual/en/pdostatement.fetchall.php