我的php脚本输出一个以[[]开头的json数组,

时间:2015-11-23 12:38:20

标签: php json

我有这个PHP脚本应该输出一个json数组,它做到了但我的json数组以[[]开头,为什么这两个额外的方括号[]?

$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "mydb";
$conn = mysql_connect($servername, $username, $password,$dbname);
    $result = mysql_query("select * from mydb.mytable" ) 

     or die(mysql_error());  

    //create an array
    $emparray[] = array();
    while($row =mysql_fetch_assoc($result))
    {
        $emparray[] = $row;
    }
    $object =   $emparray;
    echo json_encode($object) ;

0 个答案:

没有答案