0

I want a loop within a loop that can can stop the main loop when a condition is true. For example

  `payment1 = 700, Date = 15/03/2022
  payment2 = 300, Date = 4/05/2022
  payment3 = 500, Date = 1/11/2022
  Capital = 1000, Date = 01/02/2022`

I want a loop to calculate from a month interval from the capital date, if payment is made then deduct the payment from the capital else multiply the capital with interest, the loop will keep going untill capital is 0 then exit


 $ab =array("$payment");

 foreach ($ab as $val) {
  $capital -=$val;
  $interest = 0.001;
  if($val<=0){
      $newbalance=$capital*$interest;
   }
   if($capital <=0){
        break;// Stop the loop
   }
}








    $payments = [
        ['payment1' => 700, 'Date' => '15/03/2022'],
        ['payment2' => 300, 'Date' => '4/05/2022'],
        ['payment3' => 500, 'Date' => '1/11/2022'],
        ['Capital' => 1000, 'Date' => '01/02/2022'],
    ];

    $capital = 1800;

    foreach ($payments as $a) {
        if($capital <=0){
            break;
        }

        foreach($a as $k=>$v){
            if(!is_numeric($v)){
                continue;
            }

            if(is_numeric($v)){
                $capital -=$v;
                $interest = 0.001;
            }

            if($v <=0){
                $newbalance=$capital*$interest;    
            }
        }
    }
Mehrwarz
  • 413
  • 1
  • 10
Segun
  • 29
  • 5

0 Answers0