0
我試圖轉換我的郵編和JSON對象數組中的城鎮,但我想我沒有做正確的,我需要它爲我的自動完成功能。轉換對象數組
這裏是我的代碼:
$sql = "SELECT * FROM uk_postcodes";
$result = mysqli_query($connection, $sql) or die("Error " . mysqli_error($connection));
$dname_list = array();
while($row = mysqli_fetch_array($result))
{
// [ { label: "Choice1", value: "value1" }, { label: "Choice2", value: "value2" } ]
$dname_list[] = "{label:".$row['postcode'].","."value:".$row['town']."}";
}
header('Content-Type: application/json');
echo json_encode($dname_list);
'$ dname_list [] =陣列( '標籤'=> $行[ '郵政編碼'], '值'=> $行[ '鎮']) ;' – AbraCadaver