使用while循环和json编码的数组索引在PHP中不起作用

This code when run on our localhost works:

if($result){
     if($tmp=$result->num_rows){
         while($row = $result->fetch_assoc()) {
             $myArray[]  = $row;
         }
       echo json_encode($myArray[0]);
     }
}

But, when it is run on the server (Godaddy Hosting) it reutrns a null value.

Check if you have any results in your database. If yes, then check if you have any non-ASCII caracters which makes your json_encode returning false, or encode them with utf8_encode :

while($row = $result->fetch_assoc()) {
      $myArray[]  = array_map('utf8_encode', $row);
}

You can also use json_last_error to help you debbuging.