php-8isnumeric

Using is_numeric to replace a string


In the course of converting some variables from an API, I need to check if the API is returning a string, such as " N/A", and not a number such as "824". This is the code that I'm attempting to use where, if the variable from the API is a number, leave it alone, otherwise, change it to a = (Zero)

$weather["barometer_min"] = (is_numeric($weewxapi[36]) ? number_format($weewxapi[36],0) : "0");

It does not appear to be working, however, it is not throwing any errors. Can anyone guide me in the right direction?


Solution

  • As shown by Syscall, using 3v4l.org, the code works.