Как объединить ассоциативные массивы с разными ключами?

Я пытаюсь объединить 5 ассоциативных массивов, которые имеют разные ключи. Это результат использования массива на 5 массивах.

array_merge($bucketExlData1, $bucketExlData2, $bucketExlData3, $bucketExlData4, $bucketExlData5)

результат

array:5 [▼
0 => array:1 [▼
"Name" => "John Test"]
1 => array:1 [▼
"Archived-On" => "2016-05-02 18:20:26"]
2 => array:8 [▼
"Phone" => "2132918968""DOB" => "1800-01-01 00:00:00""Referred-By-Practice" => "-""Referred-By-Provider" => "-""Last-Scheduled-To-Practice" => "-""Last-Scheduled-To-Provider" => "-""Last-Scheduled-To-Location" => "-""Last-Scheduled-Date-of-Service" => "-"]
3 => array:1 [▼
"Archived-Reason" => "no-need-to-schedule"]
4 => array:1 [▼
"Notes" => "done"]
]

Я хочу сделать этот массив как

array:5 [▼
"Name" => "John Test""Archived-On" => "2016-05-02 18:20:26""Phone" => "2132918968""DOB" => "1800-01-01 00:00:00""Referred-By-Practice" => "-""Referred-By-Provider" => "-""Last-Scheduled-To-Practice" => "-""Last-Scheduled-To-Provider" => "-""Last-Scheduled-To-Location" => "-""Last-Scheduled-Date-of-Service" => "-""Archived-Reason" => "no-need-to-schedule""Notes" => "done"]

1

Решение

Я предполагаю, что ваш массив такой

$arrayName = array(
'0' => array("Name" => "John Test"),
'1' => array("Archived-On" => "2016-05-02 18:20:26"),
'2' => array(
"Phone" => "2132918968",
"DOB" => "1800-01-01 00:00:00",
"Referred-By-Practice" => "-",
"Referred-By-Provider" => "-",
"Last-Scheduled-To-Practice" => "-",
"Last-Scheduled-To-Provider" => "-",
"Last-Scheduled-To-Location" => "-",
"Last-Scheduled-Date-of-Service" => "-")
);

Тогда попробуй array_reduce

$result = array_reduce($arrayName, 'array_merge', array());

Выход

Array (
[Name] => John Test
[Archived-On] => 2016-05-02 18:20:26
[Phone] => 2132918968
[DOB] => 1800-01-01 00:00:00
[Referred-By-Practice] => -
[Referred-By-Provider] => -
[Last-Scheduled-To-Practice] => -
[Last-Scheduled-To-Provider] => -
[Last-Scheduled-To-Location] => -
[Last-Scheduled-Date-of-Service] => -
)
2

Другие решения

Попробуйте еще раз с

array_merge_recursive($bucketExlData1, [
$bucketExlData2,
$bucketExlData3,
$bucketExlData4,
$bucketExlData5
]);

Или же

array_merge_recursive(
$bucketExlData1,
$bucketExlData2,
$bucketExlData3,
$bucketExlData4,
$bucketExlData5
);

Определение функции здесь: array_merge_recursive

1

По вопросам рекламы [email protected]