我从数据库中得到2个数组,在这两个数组中都有一个capital_payment,两者都是80。所以我想要完成的是,用户给出了我从$ amount获得的输入,90,然后我只选择小于90的行,如果用户选择160或160+我返回两行,如果用户选择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数组也不对。
答案 0 :(得分:1)
做了一些新的改变!希望这有效!
$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'];
}