$array = array(
array(
'http://www.example.com/index.php',
'www.example.com/index.php',
'www.example.com/forum/index.php'
),
array('http://', ""),
array('www.example.com'),
array('example.'),
array('com'),
array('/index.php', '/forum/index.php')
);
$NewArr = array(2 => $array[2]);
foreach($array as $k => $arr){
if($k != 2){
$NewArr[$k] = array();
foreach($arr as $key => $tag){
foreach($array[2] as $if){
if(preg_match("/".preg_quote($if)."/i", $tag)){
$NewArr[$k][count($NewArr[$k]) + 1] = $tag;
continue 2;
}
}
}
}
}
print_r($NewArr);