我需要一个以下结构的数组:
Array
(
[www.example.com] => Array
(
[0] => http://www.example.com/
[1] => http://www.example.com/something.html
[2] => http://www.example.com/anything.html
)
[www.beispiel.com] => Array
(
[0] => http://www.beispiel.com/product-services/
[1] => http://www.beispiel.com/non-disclosure-agreement/
)
)
作为输入数组,我有以下两个
Array ( [0] => http://www.example.com/
[1] => http://www.example.com/something.html
[2] => http://www.example.com/anything.html
[3] => http://www.beispiel.com/product-services/
[4] => http://www.beispiel.com/non-disclosure-agreement/
)
和
Array ( [0] => www.example.com [1] => www.beispiel.com )
此刻我有这样的事情:
Array
(
[0] => Array
(
[www.example.com] => http://www.example.com/
)
[1] => Array
(
[www.example.com] => http://www.example.com/something.html
)
[2] => Array
(
[www.example.com] => http://www.example.com/anything.html
)
[3] => Array
(
[www.beispiel.com] => http://www.beispiel.com/product-services/
)
[4] => Array
(
[www.beispiel.com] => http://www.beispiel.com/non-disclosure-agreement/
)
)
是可能的还是我错过了一些关于php的信息(例如key不能是解析的url(主机))?
答案 0 :(得分:1)
尝试:
$arr1 = array('http://www.example.com/','http://www.example.com/something.html','http://www.beispiel.com/product-services/' ...); // 1st input array
$arr2 = array('www.example.com', 'www.beispiel.com'); // 2nd input array
$arr1_val = array_values($arr1);
foreach($arr2 as $v) {
foreach($arr1 as $m) {
if(strpos($m, $v) !== FALSE)
$new_arr[$v][] = $m;
}
}
答案 1 :(得分:0)
这是不可能的。相同的命名规则适用于数组键,与变量一样。