Oihana PHP

deepJsonSerialize.php

Table of Contents

Functions

deepJsonSerialize()  : mixed
Recursively serialize all JsonSerializable values within an array or object.

Functions

deepJsonSerialize()

Recursively serialize all JsonSerializable values within an array or object.

deepJsonSerialize(mixed $value[, int $currentDepth = 0 ]) : mixed

This function traverses arrays and objects at any depth, and whenever it finds a value that implements JsonSerializable, it calls jsonSerialize() on it.

Parameters
$value : mixed

The value to serialize.

$currentDepth : int = 0

Internal recursion counter (default 0).

Tags
example
$data =
[
    'user' => new User(),       // implements JsonSerializable
    'tags' => ['a', 'b'],
];

$result = deepJsonSerialize($data);
// All JsonSerializable objects will be converted to arrays/values recursively
author

Marc Alcaraz (ekameleon)

since
1.0.6
Return values
mixed

The value with all JsonSerializable elements serialized.


        
On this page

Search results