警告:count()最多需要2个参数,给定3个

时间:2017-05-26 02:38:13

标签: php arrays count elements

如何让count()计算一组数组中的所有元素?

$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
$b[0] = 2;
$b[1] = 4;
$b[2] = 6;
$c[0] = 8;
$c[1] = 9;
$c[2] = 10;
$result = count($a, $b, $c);

echo $result;

1 个答案:

答案 0 :(得分:2)

count()期待一个或两个参数,但你给它三个。

你可以使用,

array_sum(array_map('count', [$a, $b, $c]));