php统计全部字符在字符串中出现的次数

WBOY
Release: 2016-06-13 10:30:42
Original
1163 people have browsed it

php统计所有字符在字符串中出现的次数

效果如图



算法:

循环一次字符串(本例的$str),把出现过的字符串记录在一个数组(如本例的$strRecord)内,如果已经此记录函数已经有,则不记录;

在每个字符串时,拿来与记录数组的值进行比较(本例的$strRecord[]['key']),如果记录里的某个值和这个字符串一样,就记录次数+1(本例的$strRecord[]['count']);

当然,设置一个变量,默认为false(如本例的$found),记录每次比较完,如果记录数组已经有这个值,就设置为true,通过这个标记,把没有遇到过的数组记录到数组里

代码:


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 [email protected]
Latest Issues
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!