PHP - json_encode
Trieda
Metóda - json_encode
(PHP 5 >= 5.2.0, PECL json >= 1.2.0, PHP 7)
Converts a PHP variable into its JSON representation. When converting an array which indexech are not a continuous numeric sequence starting with 0, all the indexes will be encoded as strings.
Procedurálne
- function json_encode (mixed $value, int $depth = 512) : string
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $value | mixed | The value being encoded in the UTF-8 format. | |
| $depth | int | 512 | The depth limit of the recursion. |
Mávratovej hodnoty
Vracia: string
Returns the JSON representation of the PHP variable. Returns
false in case an error occurred.
Príklady
<?php
$myArray = [
"name" => "John",
"age" => 42,
"male" => true
];
var_dump(json_encode($mojePole));
var_dump(json_encode(42));
var_dump(json_encode(true));
var_dump(json_encode("hello world!"));
Súvisiace manuály
- function json_decode (string $json, bool $assoc = false, int $depth = 512, int $options = 0) : mixed
- function serialize (mixed $value) : string
