<?php
$array1 = [
1 => "tenants",
2 => "modules",
];
$array2 = [
"prefix" => "tenants",
"slug" => "tenants",
"child" => [
[
"prefix" => "modules/{id}",
"slug" => "modules"
],
[
"prefix" => "fetch/{id}",
"slug" => "fetch"
],
],
];
function getFromChild($item, $asd) {
if (!is_array($item)) return [];
$res = [];
if ($item["slug"] == $asd)
$res[] = $item['prefix'];
if (isset($item['child']))
foreach($item['child'] as $child)
$res = array_merge($res, getFromChild($child, $asd));
return $res;
}
$res = [];
foreach ($array1 as $asd) {
$res = array_merge($res, getFromChild($array2, $asd));
}
print_r($res);
preferences:
14.58 ms | 405 KiB | 5 Q