[Solved] json_encode with object oriented PHP [closed]


You don’t need Object Oriented to do that :

$array = array("usa" => array(
               "label"=>"USA", 
                "data" => array(
                                array("1988","483994"),
                                array("1989","457645") //etc
                          )
                )
          );
 echo json_encode($array);

The same works back with the json string like this :

$string = '{
  "usa": {
    label: "USA",
    data: [[1988, 483994], [1989, 479060], [1990, 457648], [1991, 401949], [1992, 424705], [1993, 402375], [1994, 377867], [1995, 357382], [1996, 337946], [1997, 336185], [1998, 328611], [1999, 329421], [2000, 342172], [2001, 344932], [2002, 387303], [2003, 440813], [2004, 480451], [2005, 504638], [2006, 528692]]
  }

  // skipped other data
}';

print_r(json_decode($string, true)); //Will show you the previous array

See php docs.

3

solved json_encode with object oriented PHP [closed]