php – Create a tree menu with dynamics links

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')(1)
  $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 .= "<ul>n";
      foreach ($category('parent_cats')($parent) as $cat_id) {
        if (!isset($category('parent_cats')($cat_id))) {
          $html .= "<li>n  <a href="https://webmasters.stackexchange.com/" . $category("categories')($cat_id)('category_link') . "'>" . $category('categories')($cat_id)('category_name') . "</i></a>n</li> n";
        }
        if (isset($category('parent_cats')($cat_id))) {
          $html .= "<li>n <h3> <a href="https://webmasters.stackexchange.com/" . $category("categories')($cat_id)('category_link') . "'>" . $category('categories')($cat_id)('category_name') . "</a></h3> n";
          $html .= buildCategory($cat_id, $category);
          $html .= "</li> n";
         
        }
      }
      $html .= "</ul> n";
    }
    return $html;
  }
  ?>

How can I make dynamic links for all categories without getting data from a database, or if there is any way to make dynamic links from a database guide me.