私はforeachをループしています。このようなロジックを作る必要があります: 反復が最後でない場合。価格を集める。反復が最後のときです。集められた価格で合計から減算する。最後の反復価格を除きます。私は次のコードを持っていない。しかし、それは動作していません。最後の反復を除いてforeachループで何かを決定して行います。
$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++;
}
EDIT:すべての対話EXECPT LASTの価格を集めしようとしている:
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;
}
あなたは '$ i'と' $ count'に総数を持っていますので、 'if($ i == $ counter){}'は最後のものを捕まえますか? – Egg
最初のループの '$ i> $ count'では、$ iは0です。したがって、$ countよりもどのように大きいでしょうか? –
私の編集を参照してください。私は最初にすべてのexecptを集める必要があります。 '$ reslist'には最後の – Prague2