Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created March 23, 2017 15:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save phpfiddle/9789c04025367bd5c3ec569ef61be8e1 to your computer and use it in GitHub Desktop.
<?php
// chkNull function similar to JS used in calculations
function chkNull($val) {
return (($val !== '0' && $val !== (int)0 && $val !== (float)0
&& ($val == '' || $val == null || $val === 'NaN' || is_nan($val) || !is_numeric($val)))
? NAN : $val*1);
}
$arg0 = '';
$arg1 = '';
$parseVar = (((chkNull(($arg0))>0)?(1):(0))*1+1*((chkNull(($arg1))>0)?(1):(0)));
print "ParseVar: $parseVar <br>";
print "IsNumeric? " . is_numeric($parseVar) . "<br>";
print "IsNaN? " . ( is_nan($parseVar) ? 'true' : 'false') . "<br>";
$result = ((is_numeric($parseVar) && is_nan($parseVar) === false) ? $parseVar : '');
print "Result: " . $result . "<br>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment