get main URL from subdirectory with php

site_url gets you the current sites URL, but you can get the site URL of the root blog at / via get_site_url by passing its ID, which is likely to be 1, e.g.:

$url = get_site_url( 1 );

As an aside, you may find switch_to_blog and restore_current_blog to be useful, just know that they’re not cheap to call, and it won’t load code from the other blog/site, if the other site relies on a custom plugin or filters it won’t be present unless it’s also present on the current site.