我試圖生成以下JSON數據:從PHP foreach
循環看起來像這樣內PHP JSON編碼
[
{
"ID": "A1000",
"name": "John Simpson",
"serialID": "S41234",
"tagID": "ABC6456"
},
{
"ID": "B2000",
"name": "Sally Smith",
"serialID": "B5134536",
"tagID": "KJJ451345"
},
{
"ID": "A9854",
"name": "Henry Jones",
"serialID": "KY4239582309",
"tagID": "HYG452435"
}
]
:
foreach($records as $record) {
$ID = $record->getField('propertyID');
$name = $record->getField('assignedName');
$serialID = $record->getField('serial');
$tagID = $record->getField('tag');
}
我已經嘗試使用:
$arr = array('ID' => $ID, 'name' => $name, 'serialID' => $serialID, 'tagID' => $tagID);
它適用於循環內的每個記錄,但不能計算出連接的語法t一起擺成一個單一的JSON數據字符串?
不會覆蓋'$ arr'每次迭代中,只需添加'[]' – Ghost