php - How to create comma separated list from array and return as json enode array -
i trying create json comma delimited string.now code this
$sql="select pri_name nri_privilege"; $getvalue=mysqli_query($mysqli,$sql); while($result=mysqli_fetch_assoc($getvalue)) { $getallresults[]=$result; } foreach($getallresults $rereult) { print_r($rereult); name =$rereult['pri_name']; name .=$name .','; //echo $name; //echo json_encode($name); }
i fetching data database , loop inside foreach. how create json comma delimited string?
based on title of post described.
$array = ["foo", "bar", "bat"]; //some array form e.g. db $glued = implode(",", $array); //implode , $json = json_encode($glued); //and json encode
what think want this:
$array = ["foo", "bar", "bat"]; //some array form e.g. db $json = json_encode($array); //json encode array without step 2.
guess want send json
encoded array on wire somewhere else. in case no need implode
or explode
.
Comments
Post a Comment