title: PHP url array search and return closest url
body: <p>I have the following array with urls</p>
  
  <pre><code>$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' );
  </code></pre>
  
  <p>Then I have a variable</p>
  
  <pre><code>$url = 'http://localhost/my_system/users/by_letter/s';
  </code></pre>
  
  <p>I need a function that will return the closest url from the array if $url does not exist. Something like </p>
  
  <pre><code>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/'
  </code></pre>