Моя рекурсивная функция возвращает все дочерние элементы меню, но я хочу иметь только последние дочерние элементы массива, вот мой код:
function test($pid){
$arr = array();
$sql = "SELECT * FROM wp_term_taxonomy WHERE parent=$pid && taxonomy='product_cat'";
$result = mysqli_query($GLOBALS['conn'], $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$term_taxonomy_id = $row['term_taxonomy_id'];
$arr[$row['term_taxonomy_id']] = test($row['term_taxonomy_id']);
}
}
return $arr;
}
Текущий вывод:
{"26":{"194":[],"195":[],"196":[],"197":[],"198":[],"199":[],"200":[]},"30":{"201":[],"202":[],"203":[],"204":[],"205":[],"206":[],"207":[]},"32":{"217":[],"218":[],"219":[],"220":[],"221":[],"222":[],"223":[],"224":[],"225":[]},"35":{"208":[],"209":[],"210":[],"211":[],"212":[],"213":[],"214":[],"215":[],"216":[]},"38":{"226":[],"227":[],"228":[],"229":[],"230":[],"231":[],"232":[],"233":[],"234":[],"235":[],"236":[],"237":[]},"41":{"238":[],"239":[],"240":[]},"43":{"241":[],"242":[],"243":[],"244":[],"245":[],"246":[],"247":[]},"45":{"248":[],"249":[],"250":[],"251":[],"252":[],"253":[],"254":[],"255":[],"256":[]},"47":{"257":[]}}
Ожидаемый результат:
{"194","195","196","197","198","199","200","201,"202","203","204","205","206","207","217","218","219","220","221","222","223","224","225","208","209","210","211","212","213","214","215","216","226","227","228","229","230","231","232","233","234","235","236","237","238","239","240","241","242","243","244","245","246","247","248","249","250","251","252","253","254","255","256","257"}