在 php 中,我正在制作一个要转换为 JSON 字符串的数组。
这有效,如果我对它们进行硬编码:
$data = array(
'firstname' => mysql_result($recordset, 0, 'first name'),
'lastname' => mysql_result($recordset, 0, 'last name'),
'email' => mysql_result($recordset, 0, 'email address'),
'password' => mysql_result($recordset, 0, 'password'),
'phone' => mysql_result($recordset, 0, 'mobile number'),
'website' => mysql_result($recordset, 0, 'website link'),
'type' => mysql_result($recordset, 0, 'type_id'),
'active' => mysql_result($recordset, 0, 'active'),
'datejoined' => mysql_result($recordset, 0, 'date joined'),
'dateleft' => mysql_result($recordset, 0, 'date left'),
'datelastactive' => mysql_result($recordset, 0, 'date last active'),
'status' => mysql_result($recordset, 0, 'status'),
'biotext' => mysql_result($recordset, 0, 'bio text'),
'picURL' => $picURL
);
但是如果我尝试一个循环
$data = array();
for ($i = 0; $i < $num_records; $i++) {
array_push($data, "location{$i}" => mysql_result($recordset, $i, 'location'));
}
我得到错误
Parse error: syntax error, unexpected T_DOUBLE_ARROW
有谁知道如何解决这一问题?
谢谢