NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - json_encode

Trieda

Koreň \ Bez triedy

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ázovDátový typPredvolená hodnotaPopis
$valuemixed

The value being encoded in the UTF-8 format.

$depthint 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
      Aktivity