Javascript graphs from a list (PHP)

I pay promptly though paypal. Only Paypal at the moment.

I need a PHP function. This is not hard but you have to pay attention to details

That function will get a list of domains as input. For example:
example.com
example.example.com
example2.example.com
example.test.com

That function will output a valid json to be used in a collapsable tree:
https://observablehq.com/@d3/collapsible-tree?collection=@d3/d3-hierarchy

Not all the domains are give, some are implied….

Javascript graphs from a list (PHP)