JSON encode wrapper
- missing or broken in some php 5.x versions
public static json_encode ( mixed $value ) : string | ||
$value | mixed | |
return | string |
$data = array( 'name' => 'John Doe', 'email' => 'john.doe@email.com', 'age' => 30 ); $jsonData = json_encode($data); echo $jsonData;
{"name":"John Doe","email":"john.doe@email.com","age":30}
class Person { public $name; public $email; public $age; } $person = new Person(); $person->name = 'John Doe'; $person->email = 'john.doe@email.com'; $person->age = 30; $jsonData = json_encode($person); echo $jsonData;
{"name":"John Doe","email":"john.doe@email.com","age":30}In both examples, the "json_encode" function is used to encode a PHP variable into a JSON format string. The resulting string can be used for data exchange between different programming languages or applications. The "json_encode" function is part of the common package library in Piwik/Matomo.
public static json_encode ( mixed $value ) : string | ||
$value | mixed | |
return | string |