How to use ctype_digit() to check if every character in a string is a decimal digit in PHP

1 Answer

0 votes
$str = array('1234', '3.14', 'F35');
foreach ($str as $s) 
{
    if (ctype_digit($s)) 
        echo "string: $s - include only digits <br />";
    else 
        echo "string: $s - NOT include only digits <br />";
}


/*
run: 

string: 1234 - include only digits
string: 3.14 - NOT include only digits
string: F35 - NOT include only digits 

*/

 



answered Jun 6, 2016 by avibootz
...