我是 PHP 的新手。谁能告诉我如何使用函数来安排以下关联数组?$ownerfiles = ["Input.txt" => "Randy", "Code.py" => "Stan", "Output.txt" => "Randy"];
$ownerfiles = ["Randy" => ["Input.txt", "Output.txt"], "Stan" => ["Code.py"]];
1 回答
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
我测试了下面的代码,它有效。我让它尽可能短。
$ownerfiles = ["Input.txt" => "Randy", "Code.py" => "Stan", "Output.txt" => "Randy"];
foreach ($ownerfiles as $key => $value) {
$new_arr[$value][]=$key;
}
print_r($new_arr);
// Output:
//Array ( [Randy] => Array ( [0] => Input.txt [1] => Output.txt ) [Stan] => Array ( [0] => Code.py ) )
- 1 回答
- 0 关注
- 68 浏览
添加回答
举报
0/150
提交
取消