I have the following array with urls
$data = Array ( 'http://localhost/my_system/users',
'http://localhost/my_system/users/add_user',
'http://localhost/my_system/users/groups',
'http://localhost/my_system/users/add_group' );
Then I have a variable
$url = 'http://localhost/my_system/users/by_letter/s';
I need a function that will return the closest url from the array if $url does not exist. Something like
function get_closest_url($url,$data){
}
get_closest_url($url,$data); //returns 'http://localhost/my_system/users/'
$url2 = 'http://localhost/my_system/users/groups/ungrouped';
get_closest_url($url2,$data); //returns 'http://localhost/my_system/users/groups/'
$url3 = 'http://localhost/my_system/users/groups/add_group/x/y/z';
get_closest_url($url3,$data); //returns 'http://localhost/my_system/users/groups/add_group/'