字符串匹配有关问题:求大神指导

WBOY
Release: 2016-06-13 12:20:29
Original
845 people have browsed it

字符串匹配问题:求大神指导。
$a="1,2,3,4,5"
$b="1,2,3,4,6"
$c="1,2,4,5,6"
$d="2,3,4,5,6"
$f="7,8,9,10,11"
如何判断出$b,$c,$d,$f和$a的相似度呢?然后,判断出他们的百分比。

------解决思路----------------------
前提:
1.都能以,拆分
2.拆分后的数量必须相同
3.不进行顺序比较

<br />function similarity($a,$b)<br />{<br />	$a_arr=explode(',',$a);<br />	$b_arr=explode(',',$b);<br />	$num=count(array_intersect($a_arr,$b_arr));<br />	$count=count($a_arr);<br />	return ($num/$count*100).'%';<br />}<br /><br />$a="1,2,3,4,5";<br />$b="1,2,3,4,6";<br />$c="1,2,4,5,6";<br />$d="2,3,4,5,6";<br />$f="7,8,9,10,11";<br /><br />echo similarity($a,$b).'<br>';<br />echo similarity($a,$c).'<br>';<br />echo similarity($a,$d).'<br>';<br />echo similarity($a,$f).'<br>';<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!