如果在重复的函数内部进行更改,则不会记住整数

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.

use global $totalcount; inside the function print_table($data)