Michael
Michael

Reputation: 55

PHP 7.4.21 - A non-numeric value encountered

I have an array with float/int values I'm trying to build into a string to encode to json but keep getting a "Warning : A non-numeric value encountered" error. Below is a stripped down version of the issue and a few things I've tried with no luck. Anyone spot any stupid mistakes or know the cause of this issue? Thanks greatly.

//I've tried casting as a string, putting the numeric value in quotes, using the strVal()    
//function to no luck.
$angle = "";
$angles2 = array(100, 90, 80);

for ($i = 0; $i < 3; $i++)
{
    //no luck with any of these
    $angle = strVal($angles2[$i]);
    //$angle = (string)$angles2[$i];
    //$angle = "$angles2[$i]";
    //$angle = $angles2[$i] . "";
    
    $anglesStr += $angle;
}  

Upvotes: 0

Views: 2526

Answers (1)

Mark Walker
Mark Walker

Reputation: 1279

$anglesStr += $angle;

This is a numeric addition, while you want string concatenation

$anglesStr .= $angle;

eg. 2+4

The first line would return 6 while second returns 24 (if valid data types).

Upvotes: 3

Related Questions