我如何重組形式的數據通過serializeArray()
返回到更理想的結構?如何重構表單json數據?
所以現在我有:
[
{
"name":"email8",
"value":"[email protected]"
},
{
"name":"password8",
"value":"pass1"
},
{
"name":"email9",
"value":"[email protected]"
},
{
"name":"password9",
"value":"pass2"
},
{
"name":"email10",
"value":"[email protected]"
},
{
"name":"password10",
"value":"pass3"
}
]
我希望它是:
{
"[email protected]":"pass1",
"[email protected]":"pass2",
"[email protected]":"pass3"
}
我不介意,如果這是在PHP或Javascript來完成。 這裏是形式的圖像,如果有幫助:
更新: 這是我在做什麼,可能是更好的改變:
$user = WebmailAutologinUser::find(1);
$emails = array(
"[email protected]" => "pass1",
"[email protected]" => "pass2",
"[email protected]" => "pass3");
foreach ($emails as $email => $password) {
$user->autoLoginAccounts()->create([
'email' => $email,
'password' => $password
]);
}
其使用雄辯地內陷式數組進入數據庫。
所以email
和password
在DB列。
寫自定義序列? –