我有一个包含各种站点链接的多维数组,这是输出:
Array
(
[0] => Array
(
[0] => http://www.msn.com/etc
[1] => http://www.yahoo.com/etc
[2] => http://www.google.com
)
[1] => Array
(
[0] => http://www.abc.com/etc
[1] => http://www.hotmail.com/etc
[2] => http://www.hotmail.com/page/2
)
[2] => Array
(
[0] => http://www.live.com/etc
[1] => http://www.google.com/etc
[2] => http://www.stock.com
)
)
我想匹配多个 URL,这里是我的示例代码:
$sites = array("msn.com","hotmail.com","live.com");
$links = array(
array("http://www.msn.com/1","http://www.yahoo.com/etc","http://www.google.com"),
array("http://www.msn.com/2","http://www.hotmail.com/","http://www.hotmail.com/page/2"),
array("http://www.live.com/etc","http://www.google.com/etc","http://www.stock.com")
);
我需要 $sites 中的任何站点,首先它会从 $links 数组中找到 msn.com 站点,因此如果它在第一个数组($links[0])中找到 msn.com,它将不会在其他 $links 中搜索 msn.com数组但继续搜索其他(hotmail.com 和 live.com),如果它在一个数组中找到同一主机的 2 个链接,它将加入它们,这意味着如果它在一个数组元素中找到主机,它将不会搜索该主机在 $links 数组的其他元素中,因此上面的最终输出将是:
Array
(
[msn] => Array
(
[0] => http://www.msn.com/1
)
[hotmail] => Array
(
[0] => http://www.hotmail.com/
[1] => http://www.hotmail.com/page/2
)
[live] => Array
(
[0] => http://www.live.com/etc
)
)
我不确定如何执行此任务,我将不胜感激任何输入。谢谢