我是 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 關注
- 115 瀏覽
添加回答
舉報
0/150
提交
取消