Home  >  Article  >  Backend Development  >  PHP如何判断字符串中包含重复的数字

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

WBOY
WBOYOriginal
2016-06-13 11:52:371688browse

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 />

Statement:
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