PHP grouping based on array values
This example describes how PHP groups values based on arrays. We will share this with you for your reference. The details are as follows:
PHP groups values based on the array. This function is not provided in php array but is very common. I wrote a record today.
Code:
$ _ Array = array (2016, '2017-05-18 '), array (2016, '2017-05-18'), array (2016, '2017-05-18 '), array (2016, '1970-05-18 '), array (2016, '1970-05-19'), array (2016, '1970-05-19 '), array (, 44, '2017-05-19 '), array (2016, '2017-05-19'), array (2016, '2017-05-20 '), array (2016, '1970-05-20 '),); var_dump (array_val_chunk ($ _ array); function array_val_chunk ($ array) {$ result = array (); foreach ($ array as $ key => $ value) {$ result [$ value [1]. $ value [2] [] = $ value;} $ ret = array (); // convert it to a number, convenient consent to handling foreach ($ result as $ key = >$ value) {array_push ($ ret, $ value) ;}return $ ret ;}
The running result is as follows:
array(5) { [0]=> array(2) { [0]=> array(3) { [0]=> int(1) [1]=> int(11) [2]=> string(10) "2016-05-18" } [1]=> array(3) { [0]=> int(2) [1]=> int(11) [2]=> string(10) "2016-05-18" } } [1]=> array(2) { [0]=> array(3) { [0]=> int(3) [1]=> int(22) [2]=> string(10) "2016-05-18" } [1]=> array(3) { [0]=> int(4) [1]=> int(22) [2]=> string(10) "2016-05-18" } } [2]=> array(2) { [0]=> array(3) { [0]=> int(5) [1]=> int(33) [2]=> string(10) "2016-05-19" } [1]=> array(3) { [0]=> int(6) [1]=> int(33) [2]=> string(10) "2016-05-19" } } [3]=> array(2) { [0]=> array(3) { [0]=> int(7) [1]=> int(44) [2]=> string(10) "2016-05-19" } [1]=> array(3) { [0]=> int(8) [1]=> int(44) [2]=> string(10) "2016-05-19" } } [4]=> array(2) { [0]=> array(3) { [0]=> int(9) [1]=> int(55) [2]=> string(10) "2016-05-20" } [1]=> array(3) { [0]=> int(10) [1]=> int(55) [2]=> string(10) "2016-05-20" } }}