Last active
May 19, 2022 11:06
-
-
Save cp-sumi-k/db8aff36ef999a1e1ae6c1c5237fc1fc to your computer and use it in GitHub Desktop.
https://blog.canopas.com/php-useful-encoding-and-decoding-functions-you-need-to-know-210e523a065f - json_decode
This file contains hidden or 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 | |
# Example 1 (Associative array) | |
$users = '[{"id":"1","name":"John"},{"id":"2","name":"Michel"}]'; | |
var_dump(json_decode($users)); | |
/* | |
output: array(2) { [0]=> object(stdClass)#1 (2) { ["id"]=> string(1) "1" ["name"]=> string(4) "John" } | |
[1]=> object(stdClass)#2 (2) { ["id"]=> string(1) "2" ["name"]=> string(6) "Michel" } | |
} | |
*/ | |
# Example 2 (Indexed array) | |
$users = '["John","Michel"]'; | |
var_dump(json_decode($users)); | |
/* | |
output: array(2) { [0]=> string(4) "John" | |
[1]=> string(6) "Michel" | |
} | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment