Recursively deleting elements from an array
I had a need recently to delete items from a nested associative array and also any empty sub-arrays. My initial thought was to use array_walk_recursive, but this doesn't work as you can't unset nested elements and you only have access to the leaves. Clearly I needed a recursive function. I'm sure that this has been done many times before, but this is my solution: /** * Remove any elements where the callback returns true *… continue reading.