I am looping a foreach and i need to make some logic like this:
if the iteration is not the last. Gather up the prices. when the iteration is the last. subtract from the total with the gathered up prices. except the last iteration price. I got the following code not. but it's not working.

```
    $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: TRYING TO GATHER UP PRICES FOR ALL INTERACTIONS 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;
            }

```