build json array in php dynamically

前端 未结 4 1043
借酒劲吻你
借酒劲吻你 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:04

    Why not create your array as you just have done but then pass the array through json_encode?

    If you want a multi-dimensional array, try

    $array[] = array("key1" => value1, "key2" => value2);
    

提交回复
热议问题