User Tools

Site Tools


uphp:functions:is_numeric

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
uphp:functions:is_numeric [2017/03/10 09:57]
jeff
uphp:functions:is_numeric [2021/09/13 05:57] (current)
Line 1: Line 1:
 ======is_numeric====== ======is_numeric======
 +
 <badge>WMPRO, WMMINI FW >= 1.0</badge> <badge>WMMEGA FW >= 2.0</badge> <badge>WMPRO, WMMINI FW >= 1.0</badge> <badge>WMMEGA FW >= 2.0</badge>
  
-Return 1 if the value is numeric (integer, float or numeric string)+<html>Check if value is numeric (<b><span style="color:green">int<span style="color:black"></b><b><span style="color:green">float<span style="color:black"></b> or numeric <b><span style="color:green">string<span style="color:black"></b>)</html>
  
 ====Description==== ====Description====
-<well size="sm"><html><span style="font-size:125%;color:green;">int + 
-<span style="color:black;"></html>[[is_numeric]] +<well size="sm"><html> 
-<html>+<span style="font-size:125%;color:green">int 
-<span style="color:green;">mixed +<span style="color:black">is_numeric ( 
-<span style="color:blue;">$value +<span style="color:green">mixed 
-<span style="color:black;">)+<span style="color:blue">$value 
 +<span style="color:black">)
 </html></well> </html></well>
  
-Check if a value is numeric+Check to see if a value is numeric
  
-====Parameters==== +====Parameter====
-<html><span style="color:blue;"><b>value</b><span style="color:black;"></html>:  Variable or expression to be evaluated+
  
-====Return Value==== +<html><b><span style="color:blue">$value<span style="color:black"></b></html>:  Variable or expression to be evaluated 
-1 (true) if numeric, 0 (false) if not numeric (arrays always return 0)+ 
 +====Return Values==== 
 + 
 +<html><b><span style="color:green">Integer<span style="color:black"></b></html>:  1 (true) if numeric, 0 (false) if not numeric (arrays always return 0)
  
 ====Examples==== ====Examples====
-**Example #1** 
  
 <code php> <code php>
 <? <?
-$f=1.0; +  $f=1.0; 
-print(is_numeric($f));   //outputs 1, $f is a float +  print(is_numeric($f));   // outputs 1, $f is a float 
-$i=1; +  $i=1; 
-print(is_numeric($i));   //outputs 1, $i is an int +  print(is_numeric($i));   // outputs 1, $i is an int 
-$nns="cool"; +  $nns="cool"; 
-print(is_numeric($nns)); //outputs 0, $nns is a non-numeric string +  print(is_numeric($nns)); // outputs 0, $nns is a non-numeric string 
-$ns="-1.5"; +  $ns="-1.5"; 
-print(is_numeric($ns));  //outputs 1, $ns is a numeric string+  print(is_numeric($ns));  // outputs 1, $ns is a numeric string
 ?> ?>
 </code> </code>
  
-**Example #2** - Set up an array of different types of values. Then iterate through the array and output each element type, value and whether is_numeric() returns true or false:+===Set up an array of different types of valuesiterate through the arrayoutput type, value and whether is_numeric() returns true or false===
  
 <code php> <code php>
 <pre><? <pre><?
-$tests = array( +  $tests = array( 
-  1337, +    1337, 
-  0x539,         //1337 expressed in hexadecimal format +    0x539,         // 1337 expressed in hexadecimal format 
-  02471,         //1337 expressed in octal format +    02471,         // 1337 expressed in octal format 
-  0b10100111001, //1337 expressed in binary format +    0b10100111001, // 1337 expressed in binary format 
-  -25, +    -25, 
-  42.8, +    42.8, 
-  -365.0, +    -365.0, 
-  "42.9", +    "42.9", 
-  "no numbers", +    "no numbers", 
-  "123 with numbers", +    "123 with numbers", 
-  array(1,2,3), +    array(1,2,3), 
-); +  ); 
-for ($i=0;$i<sizeof($tests);$i++) { +  for ($i=0;$i<sizeof($tests);$i++) { 
-  if (is_int($tests[$i])) print("The int"); +    if (is_int($tests[$i])) print("The int"); 
-  if (is_float($tests[$i])) print("The float"); +    if (is_float($tests[$i])) print("The float"); 
-  if (is_string($tests[$i])) print("The string"); +    if (is_string($tests[$i])) print("The string"); 
-  if (is_array($tests[$i])) print("The array"); +    if (is_array($tests[$i])) print("The array"); 
-  if (!is_array($tests[$i])) print(" '".$tests[$i]."'"); +    if (!is_array($tests[$i])) print(" '".$tests[$i]."'"); 
-  if (is_numeric($tests[$i])) { +    if (is_numeric($tests[$i])) { 
-    print(" is numeric\r\n"); +      print(" is numeric\r\n"); 
-  } else { +    } else { 
-    print(" is NOT numeric\r\n");+      print(" is NOT numeric\r\n"); 
 +    }
   }   }
-} 
 ?></pre> ?></pre>
 </code> </code>
Line 85: Line 88:
  
 ====Notes==== ====Notes====
 +
 Unlike functions [[is_int()]], [[is_float()]], [[is_string()]] and [[is_array()]] this function looks at more than just the type of the variable, it also checks strings to see if they are numeric. Unlike functions [[is_int()]], [[is_float()]], [[is_string()]] and [[is_array()]] this function looks at more than just the type of the variable, it also checks strings to see if they are numeric.
  
 ====See Also==== ====See Also====
-[[is_int()]] - Return 1 if the variable is an integer 
  
-[[is_float()]] - Return 1 if the variable is a float+[[is_int()]] - Check if variable is an <html><b><span style="color:green">integer<span style="color:black"></b></html>
  
-[[is_string()]] - Return 1 if the variable is a string+[[is_float()]] - Check if variable is a <html><b><span style="color:green">float<span style="color:black"></b></html>
  
-[[is_array()]] - Return 1 if the variable is an array+[[is_string()]] - Check if variable is a <html><b><span style="color:green">string<span style="color:black"></b></html>
  
-[[uphp:numbers|uPHP Numbers and Numeric Calculations]]+[[is_array()]] - Check if a variable is an <html><b><span style="color:green">array<span style="color:black"></b></html>
  
-[[uphp:variables|uPHP Variable Types and Limits]]+[[isset()]] - Check if a variable exists
  
-[[array()]] - Create an array with values+[[uphp:numbers|uPHP Numbers and Numeric Calculations]]
  
-[[uphp:control_structures:if]] - Flow control structure for conditional execution+[[uphp:variables|uPHP Variable Types and Limits]]
  
-[[uphp:control_structures:for]] - Flow control structure for a conditional loop+[[array()]] - Create an <html><b><span style="color:green">array<span style="color:black"></b></html>, with optional values
  
uphp/functions/is_numeric.1489139864.txt.gz · Last modified: 2021/09/13 05:56 (external edit)