Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading