简体   繁体   中英

How to check with strpos if the result is a number or empty?

Let's say my echo sometimes: 1234 And sometimes Empty.

Is there a possibility to check if its a number?

Or to check if the result is empty?

echo $check;

if(strpos($check, ' check-number/empty  ') !== false){
...to do...

我不完全了解您要做什么,但是要检查变量是否为数字,可以使用PHP内置函数is_numeric()

Check the value using an if-else statement to check if current value is null . Use is_numeric to check a value is a number.

Use this:

   if(is_numeric($check)){ 
        echo "I am a number"; 
   }

As is_numeric account if a value is null as well. All the best.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM