I want to know how to create a JSON array like this in php...
{
"roster1":{
"player0":{
"sport":"NFL",
"firstname":"Tyrod",
"lastname":"Taylor"
},
"player1":{
"sport":"NFL",
"firstname":"Lamar",
"lastname":"Miller"
}
}
"roster2":{
"player0":{
"sport":"NFL",
"firstname":"Carson",
"lastname":"Palmer"
},
"player1":{
"sport":"NFL",
"firstname":"David",
"lastname":"Johnson"
}
}
}
I know it has to be some sort of multi-dimension array I'm assuming? I've tried something like...
$obj = new stdClass();
$y = 1;
$players["player".$x]['sport'] = "NFL";
$players["player".$x]['firstname'] = "Tyrod";
$players["player".$x]['lastname'] = "Taylor";
$x++;
$players["player".$x]['sport'] = "NFL";
$players["player".$x]['firstname'] = "Lamar";
$players["player".$x]['lastname'] = "Miller";
But this seems like a terrible approach and that I'm doing something very noob. I really want to know the correct way of doing something like this.
{ }which defines a JSON object, and[ ]which defines a JSON array. I'm compiling a bit of code to achieve exactly what you need, unless the resulting JSON grimmdude replied with suits your needs.