Lets say I have this function:
function hog($i = 1) // uses $i * 0.5 MiB, returns $i * 0.25 MiB
{
$s = str_repeat(\'a\', $i * 1024 *
That has everything to do with the variable scope. Everything inside the function will be cleared once the function ends. So if you need to know how much memory is used in total you need to declare them outside the function scope. My vote would go to a single variable array for ease incase you need multiple vars. If you need just one you obviously dont need the array.
$value)
{
$alpha = memory_get_usage();
hog($key);
$iterations[$key] = memory_get_usage() - $alpha;
$outervar = array();
}
print_r($iterations);
Since we dont store the result of hog this will use 0.5mb*$i. If you also need the return value even if its not stored, first save it to $outervar['result'] or something and then return it. But then it will be counted double if you do save it.
A second option would be to gave a second parameter by reference &$memusage and use the memory_get_usage() part inside the function and store the result in the byref variable