根据代码点火器中的输入条件返回行


returning rows depending on input criteria in codeigniter

我从数据库中得到了两个数组,在这两个数组中都有一个资本支付,即80。因此,我试图实现的是,用户给出一个我从$amount中得到的90的输入,然后我只选择小于90的行,如果用户选择160或160+I返回两行,如果该用户选择159,我只返回一行。所以这基本上就是我需要遵循的标准。我正试图根据条件返回数组中的数据。但我犯了很多错误,所以需要帮助。

public function GetSellLoanData($token, $amount, $expirationDate, $radioChecked, $orig_id)
{
    $result =  $this->investment->getLoansBorrowedData($id, $orig_id);
    $foo = json_decode(json_encode($result), true);
    $amountTemp = 0;
    $data = array();
    foreach($foo as $investment)
    {
        //check if input Amount greater than $AmountTemp from for each loop
        if($amount > $amountTemp)
        {
            $data[] = $investment;      
            //DO a check to see what happens to the array data
            foreach($data[] as $check){
            }
            // see if the new array did not exceed the $amount 
            //adding rows here
            $data[] = $investment;
            }else{
                break;
            }
            $amountTemp += $investment['capital_payment'];
        }
      return $data;
    }
}    

而且我想返回所选数组中的所有其他信息,所以我想我的$data数组也不正确。

做了一些新的更改!希望这能奏效!

 $amountTemp = 0;
 $data = array();
 foreach($foo as $investment)
 {
     //check if input Amount greater than $AmountTemp from for each loop
     if($amount > $amountTemp + $investment['capital_payment'])
     {
          $data[] = $investment;      
     }else{
                break;
          }
      $amountTemp += $investment['capital_payment'];
  }