//将数组转换成1维
function format_array($arr = array()){
if (empty($arr)) return array();
if (!is_array($arr)) return array($arr);
static $result = array();
foreach($arr as $val){
if (is_array($val)){
format_array($val);
} else{
$result[] = $val;
}
}
return $result;
}
function statistics_count(){
$args = func_get_args();
$arr = format_array($args);
$result = array('string' => array(), 'number' => array());
foreach($arr as $val){
if (is_string($val)){
$result['string'][$val] = isset($result['string'][$val]) ? $result['string'][$val] + 1 : 1;
} else{
$result['number'][$val] = isset($result['number'][$val]) ? $result['number'][$val] + 1 : 1;
}
}
return $result;
}
$arr1 = array('a', 'b', array(1,2,3,4,'dd','fdf','nid','innid','iii','ieir'));
$arr2 = array('d', 'de', 'ef','2','5','8');
$arr3 = array('a', 'ef', 'r', 'q');
$arr4 = array('b', 'de', 'q', 'z');
$arr5 = array('1', 'de', 'q', '3r');
$arr6 = array(1, 1, 2, 'mn', '0y');
$arr7 = array(1, 'v2d', 'mn', '0y');
print_r(statistics_count($arr1, $arr2, $arr3, $arr4, $arr5, $arr6, $arr7));
输出:
Array
(
[string] => Array
(
[a] => 2
[b] => 2
[dd] => 1
[fdf] => 1
[nid] => 1
[innid] => 1
[iii] => 1
[ieir] => 1
[d] => 1
[de] => 3
[ef] => 2
[2] => 1
[5] => 1
[8] => 1
[r] => 1
[q] => 3
[z] => 1
[1] => 1
[3r] => 1
[mn] => 2
[0y] => 2
[v2d] => 1
)
[number] => Array
(
[1] => 4
[2] => 2
[3] => 1
[4] => 1
)
)