This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
uphp:functions:is_numeric [2017/03/10 14:04] jeff |
uphp:functions:is_numeric [2021/09/13 05:57] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ======is_numeric====== | ======is_numeric====== | ||
| + | |||
| < | < | ||
| - | Return 1 if the value is numeric (integer, float or numeric string) | + | < |
| ====Description==== | ====Description==== | ||
| - | <well size=" | + | |
| - | <span style=" | + | <well size=" |
| - | < | + | <span style=" |
| - | <span style=" | + | <span style=" |
| - | <span style=" | + | <span style=" |
| - | <span style=" | + | <span style=" |
| + | <span style=" | ||
| </ | </ | ||
| - | Check if a value is numeric | + | Check to see if a value is numeric |
| - | ====Parameters==== | + | ====Parameter==== |
| - | < | + | |
| - | ====Return | + | < |
| - | 1 (true) if numeric, 0 (false) if not numeric (arrays always return 0) | + | |
| + | ====Return | ||
| + | |||
| + | < | ||
| ====Examples==== | ====Examples==== | ||
| - | **Example #1** | ||
| <code php> | <code php> | ||
| <? | <? | ||
| - | $f=1.0; | + | |
| - | print(is_numeric($f)); | + | print(is_numeric($f)); |
| - | $i=1; | + | $i=1; |
| - | print(is_numeric($i)); | + | print(is_numeric($i)); |
| - | $nns=" | + | $nns=" |
| - | print(is_numeric($nns)); | + | print(is_numeric($nns)); |
| - | $ns=" | + | $ns=" |
| - | print(is_numeric($ns)); | + | print(is_numeric($ns)); |
| ?> | ?> | ||
| </ | </ | ||
| - | **Example #2** - Set up an array of different types of values. Then iterate through the array and output | + | ===Set up an array of different types of values, iterate through the array, output type, value and whether is_numeric() returns true or false=== |
| <code php> | <code php> | ||
| < | < | ||
| - | $tests = array( | + | |
| - | 1337, | + | 1337, |
| - | 0x539, | + | 0x539, |
| - | 02471, | + | 02471, |
| - | 0b10100111001, | + | 0b10100111001, |
| - | -25, | + | -25, |
| - | 42.8, | + | 42.8, |
| - | -365.0, | + | -365.0, |
| - | " | + | " |
| - | "no numbers", | + | "no numbers", |
| - | "123 with numbers", | + | "123 with numbers", |
| - | array(1, | + | array(1, |
| - | ); | + | ); |
| - | for ($i=0; | + | for ($i=0; |
| - | if (is_int($tests[$i])) print(" | + | if (is_int($tests[$i])) print(" |
| - | if (is_float($tests[$i])) print(" | + | if (is_float($tests[$i])) print(" |
| - | if (is_string($tests[$i])) print(" | + | if (is_string($tests[$i])) print(" |
| - | if (is_array($tests[$i])) print(" | + | if (is_array($tests[$i])) print(" |
| - | if (!is_array($tests[$i])) print(" | + | if (!is_array($tests[$i])) print(" |
| - | if (is_numeric($tests[$i])) { | + | if (is_numeric($tests[$i])) { |
| - | print(" | + | print(" |
| - | } else { | + | } else { |
| - | print(" | + | print(" |
| + | } | ||
| } | } | ||
| - | } | ||
| ?></ | ?></ | ||
| </ | </ | ||
| Line 85: | Line 88: | ||
| ====Notes==== | ====Notes==== | ||
| + | |||
| Unlike functions [[is_int()]], | Unlike functions [[is_int()]], | ||
| ====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 a variable is an < |
| - | [[is_string()]] - Return 1 if the variable is a string | + | [[is_float()]] - Check if a variable is a < |
| - | [[is_array()]] - Return 1 if the variable is an array | + | [[is_string()]] - Check if a variable is a < |
| - | [[isset()]] - Return 1 if the variable exists | + | [[is_array()]] - Check if a variable is an < |
| + | |||
| + | [[isset()]] - Check if a variable exists | ||
| [[uphp: | [[uphp: | ||
| Line 102: | Line 107: | ||
| [[uphp: | [[uphp: | ||
| - | [[array()]] - Create an array with values | + | [[array()]] - Create an < |
| - | + | ||
| - | [[uphp: | + | |
| - | + | ||
| - | [[uphp: | + | |