<?php
function isStringInt($string) {
$num = intval($string);
if ($string == $num) {
return true;
} else {
return false;
}
}
$test = array(
'0',
'-0',
'15',
'-15',
'13,4567',
'-13,4567',
'34.3453',
'-34.3453',
'23423fwwer',
'-23423fwwer',
'0xFFFFFFFF',
'-0xFFFFFFFF',
'016',
'-016',
'53.45e2',
'-53.45e2'
);
foreach ($test as $string) {
echo $string . ((isStringInt($string)) ? ' is int' : ' isn\'t int') . '<br />';
}
0 is int
-0 is int
15 is int
-15 is int
13,4567 is int
-13,4567 is int
34.3453 isn't int
-34.3453 isn't int
23423fwwer is int
-23423fwwer is int
0xFFFFFFFF isn't int
-0xFFFFFFFF is int
016 is int
-016 is int
53.45e2 isn't int
-53.45e2 isn't int
тогда так :)
<?php
function isStringInt($string) {
$num = intval($string);
if (strlen((string)$string) == strlen((string)$num)) {
return true;
} else {
return false;
}
}
$test = array(
'0',
'-0',
'15',
'-15',
'13,4567',
'-13,4567',
'34.3453',
'-34.3453',
'23423fwwer',
'-23423fwwer',
'0xFFFFFFFF',
'-0xFFFFFFFF',
'016',
'-016',
'53.45e2',
'-53.45e2'
);
foreach ($test as $string) {
echo $string . ((isStringInt($string)) ? ' is int' : ' isn\'t int') . '<br />';
}
0 is int
-0 isn't int
15 is int
-15 is int
13,4567 isn't int
-13,4567 isn't int
34.3453 isn't int
-34.3453 isn't int
23423fwwer isn't int
-23423fwwer isn't int
0xFFFFFFFF isn't int
-0xFFFFFFFF isn't int
016 isn't int
-016 isn't int
53.45e2 isn't int
-53.45e2 isn't int
Спустя 69 сек.
а если с ведущими нулями, то считается числом или нет по условию?))
Спустя 52 сек.
задание только для дестячной системы счисления? :D