<?php $data = [ "localhost/my_system/users", "localhost/my_system/users/add_user", "localhost/my_system/users/by_letter/groups", "localhost/my_system/users/add_group"]; $url = "localhost/my_system/users/by_letter/s"; function getClosestURL($url, $data){ $matches = []; $explodedURL = explode("/", $url); foreach ($data as $match) { $explodedMatch = explode("/", $match); $matches[] = array_intersect($explodedMatch, $explodedURL); } return count(max($matches)) > 0 ? implode("/", max($matches)) : false; } var_dump(getClosestURL($url, $data)); //returns localhost/my_system/users/by_letter var_dump(getClosestURL("local/no/match", $data)); //returns false
You have javascript disabled. You will not be able to edit any code.