php – hello guys please i need help i just creating tree menu but dynamics link is so hard for me

enter image description here
//create a multidimensional array to hold a list of category and parent category
$category = array(
‘categories’ => array(),
‘parent_cats’ => array()
);

//build the array lists with data from the category table
while ($row = mysqli_fetch_assoc($result)) {
//creates entry into categories array with current category id ie. $categories’categories’
$category(‘categories’)($row(‘category_id’)) = $row;
//creates entry into parent_cats array. parent_cats array contains a list of all categories with children
$category(‘parent_cats’)($row(‘parent_id’))() = $row(‘category_id’);
}

function buildCategory($parent, $category) {
$html = “”;
if (isset($category(‘parent_cats’)($parent))) {
$html .= “n”;
foreach ($category(‘parent_cats’)($parent) as $cat_id) {
if (!isset($category(‘parent_cats’)($cat_id))) {
$html .= “

  • n <a href=”https://webmasters.stackexchange.com/” . $category(“categories’)($cat_id)(‘category_link’) . “‘>” . $category(‘categories’)($cat_id)(‘category_name’) . “n
  • n”;
    }
    if (isset($category(‘parent_cats’)($cat_id))) {
    $html .= “

  • n

    <a href=”https://webmasters.stackexchange.com/” . $category(“categories’)($cat_id)(‘category_link’) . “‘>” . $category(‘categories’)($cat_id)(‘category_name’) . “

    n”;
    $html .= buildCategory($cat_id, $category);
    $html .= “

  • n”;

        }
      }
      $html .= "</ul> n";
    }
    return $html;
    

    }
    ?>

    how can i make dynamic link for all category without from database or if there is any way to make dynamic link from database guide me.