Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active December 26, 2018 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/9a2a194b45fc616e3b672af2d443b57f to your computer and use it in GitHub Desktop.
Save parzibyte/9a2a194b45fc616e3b672af2d443b57f to your computer and use it in GitHub Desktop.
<?php
$objeto = [
// Nivel 1
"idCuenta" => "123ASD",
"cliente" => "parzibyte",
"saldo" => 250.0,
"movimientos" => [
// Nivel 2
[
"tipo" => "salida",
"monto" => 125.0,
"fecha" => "2018-12-25",
"involucrados" => [
// Nivel 3
"nombre" => "Un nombre",
"idCuenta" => "456465"
]
],
[
"tipo" => "salida",
"monto" => 666.55,
"fecha" => "2018-12-26"
]
]
];
// Con profundidad 4 todo va bien
echo "Con profundidad 4:" . json_encode($objeto, 0, 4) . "\n";
# Con profundidad 4:{"idCuenta":"123ASD","cliente":"parzibyte","saldo":250,"movimientos":[{"tipo":"salida","monto":125,"fecha":"2018-12-25","involucrados":{"nombre":"Un nombre","idCuenta":"456465"}},{"tipo":"salida","monto":666.55,"fecha":"2018-12-26"}]}
// Pero si lo ponemos a 3, json_encode devuelve FALSE y no se imprime nada
echo "Con profundidad de 3:" . json_encode($objeto, 0, 3) . "\n";
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment