search

Home  >  Q&A  >  body text

Use single quotes for strings and integers, this is true for both

<?php

$str='18.8';

if(is_numeric($str)){

echo 'zheng';

}else{

echo 'jia';

}


if(is_string($str)){

echo 'zheng';

}else{

echo 'jia';

}

?>


益波益波2698 days ago1311

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-11-11 22:55:46

    • The parameter of the is_numeric() function is a number or a numeric string. Your parameter '18.8' is a numeric string and meets the conditions, so it returns "true";

    • What you want to test is '18.8', you should use: is_float() function to test. If you want to test integer, please use is_int()

    • More usage, Can parameter PHP User Manual

    reply
    0
  • Cancelreply