I am working on a project where I need to combine multiple arrays to one who has the same date. Let me show you an example
["first"]=>
{
[0]=>
{
["date"]=> "Jun 14",
["hhp_signed"]=> "0"
}
}
["second"]=>
{
[0]=>
{
["date"]=> "Jun 14",
["coupon_purchased"]=> 0
}
}
["third"]=>
{
[0]=>
{
["date"]=> "Jun 14",
["user_subscription"]=> "0"
}
}
Here is the expected result
["final"] => {
[0] => {
["date"]=> "Jun 14",
["hhp_signed"] => 0,
["coupon_purchased"] => 0,
["user_subscription"] => 0
}
[1] => {
["date"]=> "Jun 15",
["hhp_signed"] => 2,
["coupon_purchased"] => 5,
["user_subscription"] => 0
}
}
Currently I am writing values of three arrays but there could be more than three arrays may be 7 or 8
I have tried this function but it only works for two arrays, in my case, there would be more than two.
function combo($array1, $array2) {
$output = array();
$arrayAB = array_merge($array1, $array2);
foreach ( $arrayAB as $value ) {
$id = $value['date'];
if ( !isset($output[$id]) ) {
$output[$id] = array();
}
$output[$id] = array_merge($output[$id], $value);
}
return $output;
}
I really thanks you for your efforts