I have a string (url path) such as /recipes/cheese/cheese-meat-loaf and I have a giant array of paths such as
'/recipes/',
'/content/'
...
I want to take my path and find the path in the array that matches part of the path. So for this example it would match /recipes/ in the array as the path contains /recipes/, but the array may also contain /recipes/cheese/ in which case it should match that instead.
So pretty much I want to go through the path subtracting everything between the / and try and match it... So it would do
`/recipes/cheese/cheese-meat-loaf` then if not found
`/recipes/cheese/` then if not found
`/recipes/` then if not found
return default
and it would return the value in the giant array (the key is the path).
I want it to go backwards as I only want one value, and there may be multiple /recipes/*/
But I am unsure of how abouts to do this.
explodewill probably help you. And yes you probably want to use recursion for simpler code./recipes/cheese/cheese-meat-loafand/recipes/cheese-meat-loaf- which would you want to return?