Home > Software design >  PHP 7.4.21 - A non-numeric value encountered
PHP 7.4.21 - A non-numeric value encountered

Time:12-06

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;
}  

CodePudding user response:

$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).

  • Related