Last active
November 11, 2015 16:35
-
-
Save klhall1987/dbbfe562918d753cb213 to your computer and use it in GitHub Desktop.
is_numeric
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$numbers = array( | |
12, | |
1551, | |
'21', | |
'5115', | |
'I am a string', | |
); | |
//loop through the numbers array | |
foreach( $numbers as $number ){ | |
//filter if it is a number or a numeric string | |
if( is_numeric( $number ) ){ | |
echo $number . ' is numeric.' . "</br>"; | |
//otherwise output value is not a number | |
} else { | |
echo $number . ' is not number.' . "</br>"; | |
} | |
} | |
?> | |
*****Output***** | |
12 is numeric. | |
1551 is numeric. | |
21 is numeric. | |
5115 is numeric. | |
I am a string is not number. | |
**************** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment