Reputation: 68670
$revenue = $price - ( (float) $cost_price + implode(' + ', $computed['overheads']) );
.. results in a notice:
Notice: A non well formed numeric value encountered in ...
Wonder whats causing it and how can I fix it?
Upvotes: 0
Views: 481
Reputation: 5847
When you run implode
with the +
sign, it creates a string out of an array and adds +
between each item in the array, that is, it will not evaluate the code into a equation.
If you know that all the values in the array is of the float (or some numeric type) you could use the array_sum
function, which creates a sum of all the values in the array.
Something like:
$revenue = $price - ((float)$cost_price + array_sum($computed['overheads']));
Upvotes: 2