我正在撞我确信是重组数组的简单修复。对于如何向我提供数组,我别无选择:
Array
(
[author] => Array
(
[0] => John Doe
)
[journal] => Array
(
[0] => Biology
)
)
但我需要以下内容:
Array
(
[author] => John Doe
[journal] => Biology
)
我一直在研究各种路线,但我的大脑现在不是这样工作的......
$result = [];
foreach ($data as $key => $value) {
$result[$key] = $value[0];
}
var_dump($result);
<?php
function reduce_array($array) {
$new = array();
foreach($array as $key => $value) {
$new[$key] = $value[0];
}
return $new;
}
?>