Home > Backend Development > PHP Tutorial > 字符串怎么匹配数组和

字符串怎么匹配数组和

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:52:11
Original
996 people have browsed it

字符串如何匹配数组和?

本帖最后由 u014038328 于 2014-03-23 22:34:29 编辑
<br /><br /><br />$a = 'abc123';  // 字符串<br /><br /><br />如何匹配如下数组?<br /><br />Array<br />(<br />    [0] => abc123<br />    [1] => 1231231<br />    [2] => 123123123<br />    [3] => 222aads2<br />    [4] => 23232<br />    [8] => 222211<br />    [9] => asfds<br />) <br /><br />个数  前后  字母  大小写   都要匹配  <br /><br />如果匹配其中一个返回  true  否则 返回 false<br /><br /><br />
Copy after login

------解决方案--------------------
匹配是指在数组中?
in_array()?
------解决方案--------------------
$a = 'abc123';<br />$arr = Array<br />(<br />    0 => 'abc123',<br />    1 => '1231231',<br />    2 => '123123123',<br />    3 => '222aads2',<br />    4 => '23232',<br />    8 => '222211',<br />    9 => 'asfds'<br />) ;<br />if(in_array($a, $arr)){<br />	echo '匹配成功';<br />}else{<br />	echo '匹配失败';<br />}
Copy after login
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template