Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 需要删除squre括号json_encode(array())_Php_Json_Arrays - Fatal编程技术网

Php 需要删除squre括号json_encode(array())

Php 需要删除squre括号json_encode(array()),php,json,arrays,Php,Json,Arrays,下面是我的代码,它返回json数组,但我需要从响应中删除方括号 $sql = "select user_loginId,user_password from wnl_user where user_loginId='student01' and user_password='123456' and user_status='active'"; //echo $sql;die; $result = mysql_query($sql);

下面是我的代码,它返回json数组,但我需要从响应中删除方括号

$sql = "select user_loginId,user_password from wnl_user where user_loginId='student01' and user_password='123456' and user_status='active'";
            //echo $sql;die;
            $result = mysql_query($sql);

            $num_rows = mysql_num_rows($result); //function to get number of rows from result

              $posts = array();

              if($num_rows != 0)
              {
                  if(mysql_num_rows($result)) {
                    while($post = mysql_fetch_assoc($result)) {
                      $posts[] = array('status'=>'1','post'=>$post);
                    }
                  }

                  echo json_encode(array('posts'=>$posts));
              }
              else
              {
                    echo json_encode(array('status'=>"0",'data'=>"No Data Found"));
              }
回应是

{"posts":[{"status":"1","post":{"user_loginId":"student01","user_password":"123456"}}]}
我需要删除{“posts”:[这个从开始的方括号中删除,]}也从结尾删除


请帮我解决这个问题

使用,您可以删除
数组('posts')

echo json_encode($posts);
而不是

echo json_encode(array('posts'=>$posts));

使用时,您可以删除
数组('posts'

echo json_encode($posts);
而不是

echo json_encode(array('posts'=>$posts));

使用时,您可以删除
数组('posts'

echo json_encode($posts);
而不是

echo json_encode(array('posts'=>$posts));

使用时,您可以删除
数组('posts'

echo json_encode($posts);
而不是

echo json_encode(array('posts'=>$posts));
呃…
echo-json\u-encode($posts);
Uh…
echo-json\u-encode($posts);
Uh…
echo-json\u-encode($posts);