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/1e67f9acb3fb4c2b488e9241c9f70974 to your computer and use it in GitHub Desktop.
Save cp-sumi-k/1e67f9acb3fb4c2b488e9241c9f70974 to your computer and use it in GitHub Desktop.
<?php
# Example 1 (Associative array)
$users = array(array("id"=>"1", "name"=>"John"), array("id"=>"2", "name"=>"Michel"));
echo json_encode($users);
# output: [{"id":"1","name":"John"},{"id":"2","name":"Michel"}]
# Example 2 (Indexed array)
$users = array("John", "Michel");
echo json_encode($users);
# output: ["John","Michel"]
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment