There are two Arrays: {code ...} compare whether the values of Vtime in array A and Date in array B are the same. If the values are the same, merge the values (vtime, qr, Date, and Md5) into array C. If the values are different, put array A in array C. (Array A must be compared with array B. array B has only two Arrays:
===========A:array( [0] => Array ( [Vtime] => 2014-01-18 00:22:43 [qr] => 0a5500f5d5e5847209d83a7fe637a34f ) [1] => Array ( [Vtime] => 2014-01-17 00:00:00 [qr] => 218e412b1d73f771e8b01b9d1f678f5b ))===========B:array( [0] => Array ( [Date] => 2014-01-18 00:22:43 [Md5] => 0a5500f5d5e5847209d83a7fe637a34f ) [1] => Array ( [Date] => 2014-01-18 00:22:43 [Md5] => 218e412b1d73f771e8b01b9d1f678f5b ) [2] => Array ( [Date] => 2014-01-17 00:00:00 [Md5] => 218e412b1d73f771e8b01b9d1f678f5b ) [3] => Array ( [Date] => 2014-01-17 00:00:00 [Md5] => 218e412b1d73f771e8b01b9d1f678f5b ) [4] => Array ( [Date] => 2014-01-17 00:00:00 [Md5] => 218e412b1d73f771e8b01b9d1f678f5b ))
Compare whether the Vtime in array A is the same as the Date in array B. If the data is the same, merge (vtime, qr, Date, Md5) the data into array C,
If they are different, separate array A to array C.
(Array A must be compared with array B. array B will be retained to array C only when it corresponds to array)
Please help me find a solution.
Reply content:
There are two Arrays:
===========A:array( [0] => Array ( [Vtime] => 2014-01-18 00:22:43 [qr] => 0a5500f5d5e5847209d83a7fe637a34f ) [1] => Array ( [Vtime] => 2014-01-17 00:00:00 [qr] => 218e412b1d73f771e8b01b9d1f678f5b ))===========B:array( [0] => Array ( [Date] => 2014-01-18 00:22:43 [Md5] => 0a5500f5d5e5847209d83a7fe637a34f ) [1] => Array ( [Date] => 2014-01-18 00:22:43 [Md5] => 218e412b1d73f771e8b01b9d1f678f5b ) [2] => Array ( [Date] => 2014-01-17 00:00:00 [Md5] => 218e412b1d73f771e8b01b9d1f678f5b ) [3] => Array ( [Date] => 2014-01-17 00:00:00 [Md5] => 218e412b1d73f771e8b01b9d1f678f5b ) [4] => Array ( [Date] => 2014-01-17 00:00:00 [Md5] => 218e412b1d73f771e8b01b9d1f678f5b ))
Compare whether the Vtime in array A is the same as the Date in array B. If the data is the same, merge (vtime, qr, Date, Md5) the data into array C,
If they are different, separate array A to array C.
(Array A must be compared with array B. array B will be retained to array C only when it corresponds to array)
Please help me find a solution.
1, 'qr '=> 2,), array ('vtime' => 3, 'qr' => 4 ,),); $ B = array ('date' => 1, 'md5' => 2,), array ('date' => 5, 'md5' => 6,),); $ D = array (); foreach ($ B as $ B) {// date repetition is not considered. $ D [$ B ['date'] = $ B;} $ C = $ A; foreach ($ C as & $ c) {if (isset ($ D [$ c ['vtime']) {$ c = array_merge ($ c, $ D [$ c ['vtime']) ;}} unset ($ c); var_dump ($ C );
$ A = array (); // initial data $ A $ B = array (); // initial data $ B $ D = array (); foreach ($ B as $ B) {$ D ['date'] [] = $ B ['date']; $ D ['md5'] [] = $ B ['md5'];} $ D = array_combine ($ D ['date'], $ D ['md5']); foreach ($ A as & $ a) array_key_exists ($ a ['vtime'], $ D) & $ a ['md5'] = $ D [$ a ['vtime']; $ C = $;
$ C = []; $ I = 0; // traverse $ mongoray_walk ($ a, function ($ v, $ k) use ($ B, & $ c, & $ I) {// traverse $ B foreach ($ B as $ bb) {// different parts $ c [$ I] = $ v; // if the same $ v ['vtime'] ==$ bb ['date'] & list ($ c [$ I] ['date'], $ c [$ I] ['md5']) = [$ bb ['date'], $ bb ['md5']; $ I ++ ;}});