我是 PHP 的新手。誰(shuí)能告訴我如何使用函數(shù)來(lái)安排以下關(guān)聯(lián)數(shù)組?$ownerfiles = ["Input.txt" => "Randy", "Code.py" => "Stan", "Output.txt" => "Randy"];
$ownerfiles = ["Randy" => ["Input.txt", "Output.txt"], "Stan" => ["Code.py"]];
1 回答

qq_花開花謝_0
TA貢獻(xiàn)1835條經(jīng)驗(yàn) 獲得超7個(gè)贊
我測(cè)試了下面的代碼,它有效。我讓它盡可能短。
$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 關(guān)注
- 109 瀏覽
添加回答
舉報(bào)
0/150
提交
取消