Personally I like the replacement function provided by Symfony's var dumper component
Install with composer require symfony/var-dumper
and just use dump($var)
It takes care of the rest. I believe there's also a bit of JS injected there to allow you to interact with the output a bit.