Php infinite cycle

how to obtain the following data

{

title=titlevalue=iddata= pid=id

pid=0
title=value=1,data=[]

}

Php
Mar.05,2021

function tree($arr, $pid=0){
    foreach($arr as $k => $v){
        if($v['pid'] == $pid){
            $v['data'] = tree($arr, $v['id']);
            $tree[] = $v;
        }
    }
    return isset($tree)? $tree : [];
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e61839-45934.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e61839-45934.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?