基于值数组php的组密钥
我想根据值的数组创建一个带有组键的数组 例如,我有一个数组:基于值数组php的组密钥,php,Php,我想根据值的数组创建一个带有组键的数组 例如,我有一个数组: array(17) { ["user-insert-resp.php"]=> string(3) "123" ["login.php"]=> string(3) "123" ["project-list.php"]=> string(3) "123" ["logout.php"]=> string(3) "123" ["index.php"]=> stri
array(17) {
["user-insert-resp.php"]=> string(3) "123"
["login.php"]=> string(3) "123"
["project-list.php"]=> string(3) "123"
["logout.php"]=> string(3) "123"
["index.php"]=> string(3) "123"
["project-view.php"]=> string(2) "13"
["download.php"]=> string(2) "13"
["sip-creator-resp.php"]=> string(2) "23"
["project-remove-resp.php"]=> string(1) "2"
["statistic.php"]=> string(2) "23"
["graficoUsers.php"]=> string(2) "23"
["statistic-topD.php"]=> string(2) "23"
["statistic-topV.php"]=> string(2) "23"
["user-edit-resp.php"]=> string(1) "3"
["statistic-proj.php"]=> string(1) "3"
["statistic-disc.php"]=> string(1) "3"
["graficodisc.php"]=> string(1) "3"
}
我想制作另一个这样的数组:
123 => ["user-insert-resp.php","login.php","project-list.php","logout.php","sip-creator-resp.php"]
13 => ["project-view.php","download.php"]
23 => ["sip-creator-resp.php","statistic.php","statistic-topD.php","statistic-topV.php"]
2 => ["project-remove-resp.php"];
3 => ["statistic-proj.php","statistic-disc.php","graficodisc.php"]
您可以很容易地在中找到
array\u flip()
。这就是您要找的吗
$data = array();
$data["user-insert-resp.php"] = "123";
$data["login.php"] = "123";
$data["project-view.php"] = "13";
$flipped_data = array();
foreach($data as $key=>$value){
if(!isset($flipped_data[$value])){
$flipped_data[$value] = array();
}
$flipped_data[$value][] = $key;
}
结果:
Array (
[123] => Array ( [0] => user-insert-resp.php [1] => login.php )
[13] => Array ( [0] => project-view.php )
)
... 你试过的代码是什么?