I\'m trying echo the contents of an object in a JSON format. I\'m quite unexperienced with PHP and I was wondering if there is a predefined function to do this (like json_en
public function toJSON(){ $json = array( 'name' => $this->getName(), 'code' => $this->getCode(), 'msg' => $this->getMsg(), ); return json_encode($json); }
Demo: http://codepad.org/mPNGD6Gv