eozzy
eozzy

Reputation: 68670

A non well formed numeric value encountered using implode()

$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

Answers (1)

Jite
Jite

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

Related Questions