Alright, I am "kind of" new to stdClass objects in PHP and I am experimenting a bit to get an understanding in exporting data / creating APIs to get information from the database with relevant information.
So, what I want is giving a user access to some information from, lets say a database or XML-file (not everything just some parts). (In this case it's a local sqlite3 file) and I want to give the user the data in JSON-format.
What is it I need help with? For short - I would like to get some advice from you to solve the "problem" in a smarter way than I already got. (I guess my way is kind of... ugly solution.
This is the current export of the structure that I export (without JSON-encode): http://codepaste.net/965tgj
I have done this by the following way in a php file: (The $users is acually data from sqlite3.db and I do understand that to the fullest how to use, so I slimmed the code down :)
$users = array(
array(
"id" => 1,
"user" => "Xavizus"
),
array(
"id" => 2,
"user" => "Zariel"
)
);
$obj = new stdClass();
$obj->auth = true;
$obj->usercount = 2;
$obj->users = array();
for($i =0; $i < $obj->usercount; $i++){
$obj->users[] = new stdClass();
}
for($i = 0; $i < $obj->usercount; $i++) {
$obj->users[$i]->id = $users[$i]['id'];
$obj->users[$i]->user = $users[$i]['user'];
}
print_r($obj);
Is there a cleaner way to do this? or is this as cleanest I can go for?