heng tang
asked on
mapping two multidimensional array in php
I have the following 2 separates arrays and I want to add one array let say [7] element to the 2nd array if their element [1] match the [email] array value of in 1st array.Any help appreciated
1st arr=
1st arr=
Array
(
[0] => Array
(
[email] => blanklou@gmail.com
[media_id] => 50
[total_earned] => 13.15
)
[1] => Array
(
[email] => how.jimmy@gmail.com
[media_id] => 50
[total_earned] => 6.14
)
[2] => Array
(
[email] => huatheng_t@hotmail.com
[media_id] => 50
[total_earned] => 15.76
)
[3] => Array
(
[email] => siljackwong@hotmail.com
[media_id] => 50
[total_earned] => 11.46
)
[4] => Array
(
[email] => thestartest@gmail.com
[media_id] => 50
[total_earned] => 1.49
)
[5] => Array
(
[email] => tputra.utama@gmail.com
[media_id] => 50
[total_earned] => 0.45
)
)
2nd arr =Array
(
[0] => Array
(
[0] => 8
[1] => blanklou@gmail.com
[2] =>
[3] => Tay
[4] => 0.00
[5] => 2014-09-11 21:12:44
[6] => 2014-09-15 07:02:51
)
[1] => Array
(
[0] => 9
[1] => how.jimmy@gmail.com
[2] =>
[3] => How
[4] => 0.00
[5] => 2014-09-11 21:16:45
[6] => 2014-09-23 14:58:56
)
[2] => Array
(
[0] => 12
[1] => huatheng_t@hotmail.com
[2] => Huat
[3] => Heng
[4] => 1.00
[5] => 2014-09-12 13:04:59
[6] => 2014-09-15 11:12:36
)
[3] => Array
(
[0] => 13
[1] => eldy8888@gmail.com
[2] => Voon
[3] => Ming Hann
[4] => 0.00
[5] => 2014-09-12 16:20:44
[6] => 2014-09-15 09:22:38
)
[4] => Array
(
[0] => 15
[1] => huatheng@shopstylers.com
[2] => Heng
[3] => Tang
[4] => 5.00
[5] => 2014-09-13 00:23:03
[6] => 2014-09-13 10:51:44
)
[5] => Array
(
[0] => 17
[1] => siljackwong@hotmail.com
[2] => Siljack
[3] => Wong Kok Kitt
[4] => 0.00
[5] => 2014-09-15 04:27:36
[6] => 2014-09-15 09:03:04
)
[6] => Array
(
[0] => 18
[1] => ja227@hotmail.com
[2] => Ju An
[3] => Tan
[4] => 0.00
[5] => 2014-09-15 05:05:44
[6] => 2014-09-15 08:19:56
)
[7] => Array
(
[0] => 19
[1] => sakai967@hotmail.com
[2] => Tan
[3] => Yi Hoong
[4] => 0.00
[5] => 2014-09-15 07:51:46
[6] => 2014-09-15 08:06:32
)
[8] => Array
(
[0] => 20
[1] => thestartest@gmail.com
[2] => Heng
[3] => Thestar
[4] => 0.00
[5] => 2014-09-23 12:15:11
[6] => 2014-09-23 14:27:07
)
[9] => Array
(
[0] => 21
[1] => chookarchun100@gmail.com
[2] => Choo
[3] => Chun
[4] => 0.00
[5] => 2014-09-23 12:19:13
[6] => 2014-09-23 12:19:13
)
)
I tried with this code but no luck :foreach($users_all as $ukey => $usr){
$totalearned = in_array($usr[1],$sumsales_all);
var_dump(__LINE__,$usr[1], $totalearned);
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Actually I prefer to get email from arr2[1] then compare with arr1[email]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i found the solution
ASKER
I want to get the email from arr1, then check if arr2 contains this email and if yes, then add the [total_earned] of arr1 to the new element on arr1 for that email.
This is my expected result on arr2:
Open in new window