count()-计算数组的长度;
2017-06-01 本文已影响2人
彭晓华
count()
返回数组的长度;
基础语法 :
int count(array $array [,1]);
int
- 返回数组长度的整数;
array $array
- 被操作的数组;
1
- 是否递归计算数组的长度;
语法结构1:
int count(array $array);
非递归的计算数组的长度;
实例:
$a_personal_info = array(
'bill' => array(
'first_name' => 'bill_fn',
'last_name' => 'bill_ln',
'age' => 55,
'other' => array('a','b','c')
),
'tom' => array(
'first_name' => 'tom_fn',
'last_name' => 'tom_ln',
'age' => 30,
'other' => array('a','b','c')
),
'jack' => array(
'first_name' => 'jack_fn',
'last_name' => 'jack_ln',
'age' => 20,
'other' => array('a','b','c')
)
);
print_r(count($a_personal_info));
#output : 3;
语法结构2:
int count(array $array ,1);
递归的计算数组的长度-数组元素的数量;
实例:
$a_personal_info = array(
'bill' => array(
'first_name' => 'bill_fn',
'last_name' => 'bill_ln',
'age' => 55,
'other' => array('a','b','c')
),
'tom' => array(
'first_name' => 'tom_fn',
'last_name' => 'tom_ln',
'age' => 30,
'other' => array('a','b','c')
),
'jack' => array(
'first_name' => 'jack_fn',
'last_name' => 'jack_ln',
'age' => 20,
'other' => array('a','b','c')
)
);
print_r(count($a_personal_info,1));
#output : 24;