function getUrls($tree, $url = '') {
$urls = [];
foreach ($tree as $n) {
$newUrl = ($url ? $url.'/' : '').$n->url;
array_push($urls, $newUrl, ...getUrls($n->subcategories ?? [], $newUrl));
}
return $urls;
}
select * from <TABLE> where <field> regexp '^5,|,5,|,5$'