I've got this code that I use to populate a select with an ajax call from another php page:
$id = $_GET["id"];
$sql = "SELECT town_name, 
               town_code 
        FROM   tbtown 
        WHERE  area_id = '$id' 
        ORDER BY town_name";
$result = mysqli_query($conn, $sql);
$arr = array();
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
    $arr[] = $row;
}
echo json_encode($arr);
Some town_name column values, contains characters like è ì and I found that in those cases the json_encode() function set that value to NULL.
I find out also that htmlentities() function applied to every array value solve the problem.
I wonder if there is a simple way to apply htmlentities()  to the entire array. 
 
     
    