Create JSON object using PHP

前端 未结 5 665
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 00:40

How can I achieve or create this type JSON object using PHP?

{ 
    \"label\": \"Devices per year\",
    \"data\": [
        [1999, 3.0], [2000, 3.9], [200         


        
5条回答
  •  清歌不尽
    2020-12-05 01:11

    $obj = new stdClass();
    $obj->label="Devices per year";
    $obj->data = array(
        array('1999','3.0'),
        array('2000','3.9'),
        //and so on...
    );
    
    echo json_encode($obj);
    

提交回复
热议问题