Steven Sheeley
Steven Sheeley

Reputation: 49

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?

Upvotes: 0

Views: 95

Answers (1)

Steven Sheeley
Steven Sheeley

Reputation: 49

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

Upvotes: 0

Related Questions