本文介绍了PHP - 计特定阵列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能算元素数量的数组里面加上值等于一个常数?
例如,
$ myArray的=阵列(凯尔,奔,苏,菲尔,奔,玛丽,苏,奔);
我
如何直接知道奔是多少里面?
解决方案
$阵列=阵列(凯尔,奔,苏,菲尔,奔 ,玛丽,苏,奔);
$数= array_count_values($数组);
回声$计数['本'];
How can I count the number of element inside an array with value equals a constant?example,
$myArray = array("Kyle","Ben","Sue","Phil","Ben","Mary","Sue","Ben");
how can I directly know how many "Ben" is inside?
解决方案
$array = array("Kyle","Ben","Sue","Phil","Ben","Mary","Sue","Ben");
$counts = array_count_values($array);
echo $counts['Ben'];
这篇关于PHP - 计特定阵列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!