Please help, why I received Message: Array to string conversion
请帮忙,为什么我收到消息:数组到字符串转换。
Here's my code.
这是我的代码。
$remaining = 15000;
$amort = 3600;
$sales_mi = 3600;
for($remaining += $amort; $remaining > $amort; ($hi = ($remaining-=$amort) < $amort ? $remaining : $amort) .
(($hi == $sales_mi) ? $data = array('amount'=>$hi) : 'No')
);
print_r($data);
1 个解决方案
#1
0
I took the liberty of rewriting your loop to make it readable:
我冒昧地重写了你的循环,让它可读:
for($remaining += $amort; $remaining > $amort; $remaining -= $amort) {
$hi = ($remaining) < $amort ? $remaining : $amort;
$hi .= ($hi == $sales_mi) ? $data = array('amount'=>$hi) : 'No';
}
Now: In the second line of the body of the loop you are returning an array if the condition $hi == $sales_mi is true. And you are attaching that array as if it were a string (using the "." operator) to the $hi variable. That's why you have that error.
现在:在循环体的第二行中,如果条件$hi == $sales_mi是正确的,则返回一个数组。然后,您将该数组附加到$hi变量中,就好像它是一个字符串(使用“.”操作符)。这就是为什么会有这个错误。
#1
0
I took the liberty of rewriting your loop to make it readable:
我冒昧地重写了你的循环,让它可读:
for($remaining += $amort; $remaining > $amort; $remaining -= $amort) {
$hi = ($remaining) < $amort ? $remaining : $amort;
$hi .= ($hi == $sales_mi) ? $data = array('amount'=>$hi) : 'No';
}
Now: In the second line of the body of the loop you are returning an array if the condition $hi == $sales_mi is true. And you are attaching that array as if it were a string (using the "." operator) to the $hi variable. That's why you have that error.
现在:在循环体的第二行中,如果条件$hi == $sales_mi是正确的,则返回一个数组。然后,您将该数组附加到$hi变量中,就好像它是一个字符串(使用“.”操作符)。这就是为什么会有这个错误。