Skip to content

Instantly share code, notes, and snippets.

@cp-sumi-k
Last active May 19, 2022 11:06
Show Gist options
  • Save cp-sumi-k/db8aff36ef999a1e1ae6c1c5237fc1fc to your computer and use it in GitHub Desktop.
Save cp-sumi-k/db8aff36ef999a1e1ae6c1c5237fc1fc to your computer and use it in GitHub Desktop.
<?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