Ben bir foreach döngü yapıyorum ve yineleme sonuncu değilse gibi bir mantık yapmak gerekir. Fiyatları topla. yineleme son olduğunda. toplanan fiyatlar ile toplamdan çıkar. son iterasyon fiyatı hariç. Aşağıdaki kodu aldım. ama işe yaramıyor.Son yineleme dışında foreach döngüsünde bir şeyler belirleme ve yapma
$i = 0;
$credit = '';
$count = count($reslist);
foreach ($reslist as $single_reservation) {
//All of the transactions to be settled by course
//$credit = $this->Reservations_model->find_res_price($single_reservation['value']) * $this->input->post('currency_value');
if ($i > $count && $single_reservation != end($reslist)) {
$gather_sum_in_czk += $this->Reservations_model->find_res_price($single_reservation['value']) * $this->input->post('currency_value');
$credit = $this->Reservations_model->find_res_price($single_reservation['value']) * $this->input->post('currency_value');
}
//Last iteration need to subtract gathered up sum with total.
else {
$credit = $suminczk - $gather_sum_in_czk;
}
$i++;
}
DÜZENLEME: TÜM ETKİLEŞİMLERİ Execpt LAST İÇİN FİYATLAR olarak toplamak için çalışırken:
if ($i != $count - 1 || $i !== $count - 1) {
$gather_sum_in_czk += $this->Reservations_model->find_res_price($single_reservation['value']) * $this->input->post('currency_value');
$credit = $this->Reservations_model->find_res_price($single_reservation['value']) * $this->input->post('currency_value');
}
else {
$credit = $suminczk - $gather_sum_in_czk;
}
Sayaçınız '$ i' ve' $ count' içinde toplam sayımınız var, bu yüzden mutlaka bir 'if ($ i == $ counter) {}' sonuncuyu yakalayacak mı? – Egg
İlk döngüde '$ i> $ count' üzerinde, $ i, 0, dolayısıyla, $ sayısından daha büyük nasıl olabilir? –
Düzenleme bölümüne bakın. İlk önce tüm süreyi topladım. Ardından, $ dizini için son – Prague2