The json array response of the PHP Web service?

hi, friends in this service I get output, but I think different outputs let me explain

$customer_id = $_POST["customer_id"];
    $response = array();
    $qry="SELECT category FROM nesbaty_customer where c_id="".$customer_id."" ";
    $qry_res=mysqli_query($con,$qry);
    $jsonData = array();
    while ($array = mysqli_fetch_assoc($qry_res)) 
    {
        $r= $array["category"];

        $jsonData[]=explode(",",$r);

    }
    echo json_encode(array("data" =>$jsonData));
    mysqli_close($con);

I get this output

{
"data": [
    [
        "Hotel",
        "Saloon"
    ]
]

but I want this output!

{
"data": [
    [
       "category": "Hotel",
       "category": "Saloon"
    ]
]
Mar.10,2021

but it certainly won't work if the format you want is not JSON, json_encode .

if you really want this format (not JSON), you have to concatenate the strings yourself.

add that the closer JSON is:

{
    "data": [
        {"category": "Hotel"},
        {"category": "Saloon"}
    ]
}
$jsonData = array_map(function($c) { return ["category" => $c];}, explode(",", $r));
Menu