I'm new to json and decided to use it because it looks promising. How does the syntax work?
Here is my simple php script:
$usernames = array('jake', 'john', 'jackie', 'jared');
$users = array();
for($i = 0; $i < 4; $i++)
{
$users[$i]['id'] = $i;
$users[$i]['name'] = $usernames[i];
}
$data = json_encode( $users );
echo $data;
It Outputs:
{"i":{"id":3,"name":null}}
I want it to output:
[{"id": 1,"name": "jake"},{"id": 2,"name": "john"},{"id": 3,"name": "jackie"},{"id": 4,"name": "jared"}]