Skip to content

Instantly share code, notes, and snippets.

@klhall1987
Last active November 11, 2015 16:35
Show Gist options
  • Save klhall1987/dbbfe562918d753cb213 to your computer and use it in GitHub Desktop.
Save klhall1987/dbbfe562918d753cb213 to your computer and use it in GitHub Desktop.
is_numeric
<?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