Create JSON object using PHP

json, php

Solution

$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);

Problem

How can I achieve or create this type JSON object using PHP? ``` { "label": "Devices per year", "data": [ [1999, 3.0], [2000, 3.9], [2001, 2.0], [2002, 1.2], [2003, 1.3], [2004, 2.5], [2005, 2.0], [2006, 3.1], [2007, 2.9], [2008, 0.9] ] } ``` After several attempt I didn't find the solution. For example I tried this: ``` $arrayDateAndMachine = array( "1999"=>3.0, "2000"=>3.9 ); $arr = array( "label" => "Devices per year", "data" => $arrayDateAndMachine ); var_dump(json_encode($arr)); ```

Original source

Related problems