build json array in php dynamically

前端 未结 4 924
借酒劲吻你
借酒劲吻你 2021-02-13 21:15

I can create simple json objects like this:

$d = array(\'item\' => \"$name\" ,\'rate\' => \"$rating\");

But what if I want to build an ar

4条回答
  •  感情败类
    2021-02-13 22:10

    What you can do is create a php array dynamically as you want then covert it into a json array as below.

    $json_array = json_encode($array);
    

    Keep in mind that what you have provided is not a json array

提交回复
热议问题