I got this code:
$totalcount = 0;
function print_results($results) {
foreach ($results as $id => $data) {
print_table($data);
}
}
function print_table($data) {
$totalcount = $totalcount + $data['gq_maxplayers'];
}
}
printf("</tr></tbody>");
}
But if I use it, $totalcount is being reset every time I try set it. While what I need to do is to add the last $totalcount result with the current one, so if it's on the first one is 25, and the other one is 24, in the end it should be 49.
$totalcount is local to the function you use it in. You could either pass it as a parameter to the function (and return it to the parent context), make it global, or make it static to persist the value between calls.
add this line inside your function
global $totalcount;
explanation: http://www.php.net/manual/en/language.variables.scope.php
use global $totalcount; inside the function print_table($data)