Не могу использовать array_map для извлечения результатов из двух массивов

Я пытаюсь изменить ключи массива и объединить другой массив с ним.

Первый массив у меня есть:

$output = Array (
[0] => Array (
[identifier] => doi:10.1007/978-4-431-54559-0_3
[url] => Array (
[0] => Array (
[format] =>
[platform] =>
[value] => http://dx.doi.org/10.1007/978-4-431-54559-0_3
)
)
[title] => “Vision 2050” to the Rescue of a “Limited Earth”
[creators] => Array (
[0] => Array (
[creator] => Komiyama, Hiroshi
)
)
[publicationName] => Beyond the Limits to Growth
[openaccess] => true
[doi] => 10.1007/978-4-431-54559-0_3
[printIsbn] => 978-4-431-54558-3
[electronicIsbn] => 978-4-431-54559-0
[isbn] => 978-4-431-54558-3
[publisher] => Springer
[publicationDate] => 2103-11-14
[volume] =>
[number] =>
[startingPage] =>
[copyright] => ©2014 The Editor(s) (if applicable) and the Author(s)
[genre] => OriginalPaper
[abstract] => AbstractNext let us consider the second paradigm—“The Limited Earth.” The problems caused by the fact that the Earth is limited are far-reaching. These include not only energy, resources, global warming, air pollution, water pollution, ground pollution, food, and water, but also—if we think broadly—such problems as the widescale spread of infectious diseases of people and livestock. The reason is that the probability of virus mutation and transmission increases along with the probability that wild animals come into contact with livestock, livestock with other livestock, humans with livestock, and so on. And in turn, the probability of contact on the limited surface of the Earth increases in proportion to the square of the population density.
)
)

Второй массив, который я хочу объединить:

$authors = Array (
[Authors] => Array (
[0] => Array (
[0] => Array (
[author] => Array (
[first] => Komiyama
[last] => Hiroshi
)
)
)
)
)

Окончательный вывод, который я получаю, отсутствует Авторы:

Array (
[0] => Array (
[dc:identifier] => doi:10.1007/978-4-431-54559-0_3
[dc:url] => Array (
[0] => Array (
[format] =>
[platform] =>
[value] => http://dx.doi.org/10.1007/978-4-431-54559-0_3
)
)
[dc:title] => “Vision 2050” to the Rescue of a “Limited Earth”
[prism:publicationName] => Beyond the Limits to Growth
[dc:description] => AbstractNext let us consider the second paradigm—“The Limited Earth.” The problems caused by the fact that the Earth is limited are far-reaching. These include not only energy, resources, global warming, air pollution, water pollution, ground pollution, food, and water, but also—if we think broadly—such problems as the widescale spread of infectious diseases of people and livestock. The reason is that the probability of virus mutation and transmission increases along with the probability that wild animals come into contact with livestock, livestock with other livestock, humans with livestock, and so on. And in turn, the probability of contact on the limited surface of the Earth increases in proportion to the square of the population density.
[prism:doi] => 10.1007/978-4-431-54559-0_3
[authors] =>
)

Код в вопросе:

$new_array = array_map(function($tag) {
return array(
'dc:identifier' => $tag['identifier'],
'dc:url' => $tag['url'],
'dc:title' => $tag['title'],
'prism:publicationName' => $tag['publicationName'],
'dc:description' => $tag['abstract'],
'prism:doi' => $tag['doi'],
'authors' => $tag['Authors']
); }, $output, $authors);

1

Решение

Я согласен с @ahmed. Вы передаете два аргумента и принимаете один. Пожалуйста, можете ли вы попробовать следующее:

array_map(function($tag, $authors) {
return [
'dc:identifier' => $tag['identifier'],
'dc:url' => $tag['url'],
'dc:title' => $tag['title'],
'prism:publicationName' => $tag['publicationName'],
'dc:description' => $tag['abstract'],
'prism:doi' => $tag['doi'],
'authors' => $tag['Authors']
];
}, $output, $authors);

Если не нужно использовать $authors массив затем вы можете удалить как из аргументов, так и из функции обратного вызова. Кроме того, я вижу, что у вас неправильные скобки.

1

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

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector