2 Test is_numeric() function
5 /* Prototype: bool is_numeric ( mixed $var );
6 * Description: Finds whether a variable is a number or a numeric string
9 echo "*** Testing is_numeric() with valid numeric values ***\n";
10 // different valid numeric values
35 984847472827282718178,
36 -984847472827282718178,
56 0xff, // hexa decimal numbers
58 //0x1111111111111111111111,
61 01000000000000000000000,
70 2.00000000000000000000001, // a float value with more precision points
71 "1", // numeric in the form of string
75 "2974394749328742328432",
81 '2974394749328742328432',
90 /* loop to check that is_numeric() recognizes different
91 numeric values, expected output: bool(true) */
93 foreach ($numerics as $num ) {
94 echo "-- Iteration $loop_counter --\n"; $loop_counter++;
95 var_dump( is_numeric($num) );
98 echo "\n*** Testing is_numeric() on non numeric types ***\n";
100 // get a resource type variable
101 $fp = fopen (__FILE__, "r");
102 $dfp = opendir ( __DIR__ );
108 // other types in a array
109 $not_numerics = array(
115 new stdclass, // object
137 @$unset_var, // unset variable
140 /* loop through the $not_numerics to see working of
141 is_numeric() on non numeric values, expected output: bool(false) */
143 foreach ($not_numerics as $type ) {
144 echo "-- Iteration $loop_counter --\n"; $loop_counter++;
145 var_dump( is_numeric($type) );
150 // close the resources used
156 *** Testing is_numeric() with valid numeric values ***
310 *** Testing is_numeric() on non numeric types ***