$arr = array( - '1011,1003,1008,1001,1000,1004,1012',
- '1009',
- '1011,1003,1111'
- );
- $result = array();
- foreach ($arr as $str) {
- $str_arr = explode(',', $str);
- foreach ($str_arr as $v) {
- $result[$v] = isset($result[$v]) ? $result[$v] : 0;
- $result[$v] = $result[$v] + 1;
- }
- }
- print_r($result);
- echo '
'; - $set=array();
- array_walk($arr,function($c) use (&$set ) {
- $elements=explode(',',$c);
- array_walk($elements,function($d) use(&$set){
- isset($set[$d])? $set[$d]++:$set[$d]=1;
-
- });
- });
print_r($set); - echo '
'; - $arr[0] = array(1011,1003,1008,1001,1000,1004,1012);
- $arr[1] = 1009;
- $arr[2] =array(1011,1003,1111);
- function m2s($arr){
- static $new_arr = array();
- foreach($arr as $k=>$v){
- if(is_array($v)){
- m2s($v);
}else{ - $new_arr[]=$v;
- }
- }
- return $new_arr;
- }
- $arr_ = m2s($arr);
- print_r(array_count_values ($arr_));
|