0
我有對象的數組這樣如何將id設置爲對象數組中的每個新數組?
[
{
"name": "qwe",
"password": "qwe"
},
{
"name": "qwe1",
"password": "qwe1"
}
]
我需要添加id
每對「名」和「密碼」的,它必須是這樣的
[
{
"name": "qwe",
"password": "qwe"
"id":"0"
},
{
"name": "qwe1",
"password": "qwe1"
"id":"1"
}
]
我試圖運動使用foreach
$users[] = array('name' => $name, 'password' => $password);
$i = 0;
foreach ($users as $key => $value, "id" => 0) {
$value['id'] = $i;
$i++;
}
我在PHP初學者陣列,幫助please.What我做錯了什麼?
請告訴我現在的關鍵?的print_r($用戶); – clearshot66
你的foreach表達式中的',「id」=> 0'是怎麼回事? –
'$ i = 0; foreach($ users){ $ users [$ user] =「id」=> $ i; $ i ++; }' – clearshot66