We can get all child categories in PHP using recursion. Follow below example for better understanding:
public function get_child($product_categories)
{
$cat = array();
if(count($product_categories) > 0)
{
foreach($product_categories as $val)
{
$cat[$val['category_id']]['id'] = $val['category_id'];
$cat[$val['category_id']]['name'] = $val['category'];
if(count($val['subcategories']) > 0)
{
$cat[$val['category_id']]['child'] = $this->get_child($val['subcategories']);
}
}
}
return $cat;
}