2015-11-30 74 views
2

IM在我的數據庫表中檢索一些數據,比轉換成JSON,但我需要在我的PHP循環的Json編碼多維陣列格式

["postcode"=>"townName"...] 

使用這structire一個數組,但取而代之的是給我

["postcode=>townName"...] 

我的代碼:

$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)) 
    { 

     $dname_list[] = $row['postcode']."=>".$row['town']; 
    } 
    echo json_encode($dname_list); 

回答