Question about jons format how to remove single quotation marks for a numeric type
$ Arr = array ('as' => 1, 'data' => array ('id' => $ r_id, 'list' => $ zfc ));
Echo json_encode ($ arr, JSON_FORCE_OBJECT );
{
"As": 1,
"Data ":{
"ID": "111 ",
"NeedImgList": "1.jpg, 2.jpg"
}
}
How can I remove the double quotation marks "111" from the ID ???
Reply to discussion (solution)
Use the replace function to remove it.
$r_id = 111;$zfc = '123';$arr=array('as'=>1,'data'=>array('ID'=>$r_id,'List'=>$zfc));echo json_encode($arr,JSON_FORCE_OBJECT | JSON_PRETTY_PRINT);
{ "as": 1, "data": { "ID": 111, "List": "123" }}We can see that the double quotation marks of "111" are your own (string)
In this way, the writing will be gone.
$ Arr = array ('as' => 1, 'data' => array ('id' => intval ($ r_id), 'list' => $ zfc ));
Because it is character type, there are quotation marks, you can change it like this.
$arr=array('as'=>1,'data'=>array('ID'=>intval($r_id),'List'=>$zfc));echo json_encode($arr,JSON_FORCE_OBJECT);
$arr=array('as'=>1,'data'=>array('ID'=>$r_id+0,'List'=>$zfc));echo json_encode($arr,JSON_FORCE_OBJECT);
Thank you !!