Home > PHP Framework > ThinkPHP > How to determine if a variable is a number in thinkphp

How to determine if a variable is a number in thinkphp

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2022-02-15 11:53:51
Original
3923 people have browsed it

方法:1、用“protected 变量=array(array('your_variable','number','变量为数字'),)”判断;2、用“is_numeric(变量);preg_match('/^\\d+$/',变量)”判断。

How to determine if a variable is a number in thinkphp

本文操作环境:Windows10系统、ThinkPHP5 版、Dell G3电脑。

thinkphp怎么判断变量是否为数字

1、如果要用模型的自动验证,在模型中添加:

protected $_validate = array(
    array('your_variable','number','变量应为纯数字!'),
 );
Copy after login

2、如果自行验证,可以用函数或正则表达式

is_numeric($your_variable);
preg_match('/^\\d+$/',$your_variable);
Copy after login

推荐学习:《PHP视频教程

The above is the detailed content of How to determine if a variable is a number in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template