<?php
$testArray = array(
'percy' => array(
'philip' => array(
'mitch' => array(
'percy' => 'hatcherson',
'mitch' => 'anderson'
)
),
'mitch' => array(
'mitchell',
'anderson',
'percy' => array(
'percy',
'hatcherson'
),
'mitchell' => 'thomas mitchell anderson',
'percy' => 'percy philip hatcherson'
)
)
);
$newArray = array();
function recursiveArrayColumn ($array, $index, $helper = array()) {
$helper = array_column($array, $index);
foreach ($array as $k => $v) {
if (is_array($v)) {
$helper[] = recursiveArrayColumn($v, $index, $helper);
}
}
}
var_dump(recursiveArrayColumn($testArray, 'percy'));
preferences:
45.05 ms | 402 KiB | 5 Q