PHP如何判断字符串中包含重复的数字

WBOY
Release: 2016-06-13 11:52:37
Original
1659 people have browsed it

PHP怎么判断字符串中包含重复的数字?
比如我有这么一组字符串:
a01
a02
a03
a04
.......
a11
a220
a303

其中:a11,a220,a303其中都有重复的两个1,两个2,两个3.
请问怎么用语句判断出来。如字符串里有两个数字是一样的,则为真。否则为假。
------解决方案--------------------

var_dump(preg_match('/(\d).*\1/', 'a303') > 0); //bool(true) <br />var_dump(preg_match('/(\d).*\1/', 'a203') > 0); //bool(false)<br />var_dump(preg_match('/(\d).*\1/', 'a220') > 0); //bool(true)<br />
Copy after login

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!