I'm new to php but i really like like it so far!
Now i stumbled over a problem with array_merge
.
This is my code, it simply grabs each table specified in my database then makes it to a big json file.:
$tables = array("buildings", "medical", "other", "tools", "traps", "weapons");
foreach ($tables as $table) {
// Get tables from database
$sth = $db->query("SELECT * FROM $table");
$result = $sth->fetchAll();
// Merge arrays together
if ($arr === null) {
//echo "its 0 <br/> ";
$arr = array( "$table" => $result );
} else {
//echo "more than 0 <br/> ";
$arr2 = array( "$table" => $result );
$merge = array_merge($arr, $arr2);
}
} //End loop
echo $merge;
So far It's working somehow, I manage to get the first table "buildings" and the last table "weapons" to be displayed the way i want perfectly!
But I don't understand why it jumps over the other ones..
I believe it has something to do with $arr2
and that i need to specify a unique array for each of the tables. But how can i achieve this? Is this the way to go or is there a more efficient way to achieve this?
Thanks!