When you are currently using Echart to do data statistics, you encounter this scenario:
When querying user_type=2, there is no type=1 data, the page chart display when the missing data will have unnecessary trouble, so write a method to populate the data, the code is as follows:
1 /*a type that does not have a full complement group2 * $arr 1 = [' type ' =>1, ' num ' =>0],[' type ' =>2, ' num ' =>0],[' type ' =>3, ' num ' =>0]];3 * $arr 2 = [' type ' =>2, ' num ' =>216, ' user_type ' =>2],[' type ' =>3, ' num ' =>82, ' user_type ' =>2]];4 * The type data of the $ARR2 complement type=15 */6 functionFillarr ($arr 1,$arr 2,$field _arr)7 {8 if(!Count($arr 1) || !Count($arr 2))return false;9 $new _arr=$arr 1+$arr 2;Ten if($new _arr==$arr 2) One { A return $arr 2; - } - Else the { - foreach($arr 1 as&$v _arr1) - { - foreach($arr 2 as&$v _arr2) + { - $v _arr1["$field _arr[0] "] =$v _arr2["$field _arr[0] "]; + if($v _arr2["$field _arr[1] "= =$v _arr1["$field _arr[1] "]) A { at $v _arr1["$field _arr[2] "] =$v _arr2["$field _arr[2] "]; - } - } - } - return $arr 1; - } in -}
The controller call method is as follows:
1 $album _arr= [' type ' =>1, ' num ' =>0],[' type ' =>2, ' num ' =>0],[' type ' =>3, ' num ' =>0]];2 $album _curr_total_num_b=data to be queried 5 $album _curr_total_num_c=data to be queried6 7 $album _total_b= Fillarr ($album _arr,$album _curr_total_num_b, [' User_type ', ' type ', ' num ']);8 $album _total_c= Fillarr ($album _arr,$album _curr_total_num_c, [' User_type ', ' type ', ' num ']);
The results of the processing are as follows:
1 Array(size=3)20 =3 Array(size=3)4' type ' = = int 15' num ' = int 06' User_type ' =string' 2 ' (length=1)71 =8 Array(size=3)9' type ' = = int 2Ten' num ' =string' 216 ' (length=3) One' User_type ' =string' 2 ' (length=1) A2 = - Array(size=3) -' type ' = = int 3 the' num ' =string' Length=2 ' () -' User_type ' =string' 2 ' (length=1) - - Array(size=3) +0 = - Array(size=3) +' type ' = = int 1 A' num ' =string' Length=2 ' () at' User_type ' =string' 1 ' (length=1) -1 = - Array(size=3) -' type ' = = int 2 -' num ' =string' 8 ' (length=1) -' User_type ' =string' 1 ' (length=1) in2 = - Array(size=3) to' type ' = = int 3 +' num ' =string' 1 ' (length=1) -' User_type ' =string' 1 ' (length=1)
At this point, the user_type=2 type 1 data defaults to 0
Missing a certain type of data method for a full-complement group