Last active
December 26, 2018 06:07
-
-
Save parzibyte/9a2a194b45fc616e3b672af2d443b57f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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