I am looking for a solution in php
as mentioned in the accepted answer of this question:
javascript - return parent with only child that matches given s
This should do the trick.
function getParentStackComplete($search, $stack)
{
$results = [];
foreach ($stack as $i => $item) {
$results[] = $item;
$cache = $item['asset_info'];
$results[$i]['asset_info'] = [];
$found = false;
foreach ($cache as $asset) {
if (array_search($search, $asset) !== false) {
print('here' . "\n");
$found = true;
$results[$i]['asset_info'][] = $asset;
}
}
if (!$found) {
unset($results[$i]);
}
}
return $results;
}
Edit: This assumes you're calling like this getParentStackComplete('Oracle', $items['tableData'])