I bet just like for Python, there's a library for deep dictionary lookups, there's also probably an equivalent module for PHP. That would be a nice way not to have to create recursive functions that make use of loops.