This time for you to bring PHP to use the foreach Transformation array step-by-bit, PHP using a foreach conversion array of considerations, the following is the actual case, together to see.
Requirements:
The two-dimensional array $arr is converted to a two-dimensional array with ' time ' and ' type ' as the subscript and ' data ' values;
Original array:
$arr = Array ( 0 = = Array ( ' data ' = =, ' type ' = = 1, ' time ' = ' 2018-01-26 ', ), 1 =& Gt Array ( ' data ' = $, ' type ' = = 2, ' time ' = ' 2018-01-26 ', ), 2 = = Array ( ' Data ' + ', ' type ' = 2, ' time ' = ' 2018-01-27 ', ' 3 ' = Array ( ' data ' = 400, ' type ' = 3, ' time ' = ' 2018-01-27 ', ' 4 = = Array ' (' data ' = ' = ', ' type ' =& Gt 4, ' time ' = ' 2018-01-28 ', ) ;
Transformation:
foreach ($arr as $key = + $value) {$change [$value [' Time ']][$value [' type ']] = $value [' Data '];}
Results:
Array (3) {["2018-01-26"] = = Array (2) {[1] = = Int (+) [2] = Int (+)} ["2018-01-27"] = + Array (2) {[2] =&G T int (+) [3] = = Int (+)} ["2018-01-28"] = = Array (1) {[4] = Int (500)}}
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
PHP implementation of regular expression grouping capture steps in detail
PHP Mb_strpos use steps in detail