我从数据库中得到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数组也不正确。
进行了一些新的更改!希望这行得通!
$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'];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句