I have arrays generated from foreach loop with records from DB that I want to merge if email or iduser are identical. It looks like this
Array
(
[iduser] => 1
[email] => email1@example.com
[firstname] => Jan
[lastname] => Novotny
[phone] =>
[created] => 2011-10-28 16:53:33
[last_action] => 2016-08-17 12:53:08
[idclient] => 1
[vat_type] => quarterly
[eet] => 0
[accounting_type] => accountancy
)
Array
(
[iduser] => 1
[email] => email1@example.com
[firstname] => Jan
[lastname] => Novotny
[phone] =>
[created] => 2013-11-12 18:09:11
[last_action] => 2017-01-12 10:30:38
[idclient] => 3
[vat_type] => monthly
[eet] => 1
[accounting_type] => tax_registration
)
Array
(
[iduser] => 7
[email] => email2@example.com
[firstname] => Honza
[lastname] => Novak
[phone] =>
[created] => 2015-10-28 16:53:33
[last_action] => 2010-01-27 02:18:09
[idclient] => 336
[vat_type] => quarterly
[eet] => 0
[accounting_type] => tax_registration
)
desired output is something like this.
Array
(
[iduser] => 1
[email] => email1@example.com
[firstname] => Jan
[lastname] => Novotny
[phone] =>
[created] => array(
[0]=> 2011-10-28 16:53:33
[1]=> 2013-11-12 18:09:11
[last_action] => array(
[0]=> 2016-08-17 12:53:08
[1]=> 2017-01-12 10:30:38
[idclient] => array(
[0]=> 1
[1]=> 3
[vat_type] => array(
[0]=> quarterly
[1]=> monthly
[eet] => array(
[0]=> 0
[1]=> 1
[accounting_type] => array(
[0]=> accountancy
[1]=> tax_registration
)
Array
(
[iduser] => 7
[email] => email2@example.com
[firstname] => Honza
[lastname] => Novak
[phone] =>
[created] => 2015-10-28 16:53:33
[last_action] => 2010-01-27 02:18:09
[idclient] => 336
[vat_type] => quarterly
[eet] => 0
[accounting_type] => tax_registration
)
..... etc
I tried to do it by array_merge() and array_replace_recursive() but couldn't come up with solution that works and didn't find answer in already asked questions on stackoverflow. I will appreciate any help :)