Yes it does get freed.
You can check this by using:
function a() {
$var = "Hello World";
$content = "";
for ($i = 0; $i < 10000; $i++) {
$content .= $var;
}
print '<br>$content size:'.strlen($content);
print '<br>memory in function:'.memory_get_usage();
return null;
}
print '<br>memory before function:'.memory_get_usage();
a();
print '<br>memory after function:'.memory_get_usage();
output:
memory before function:273312
$content size:110000
memory in function:383520
memory after function:273352
Before the function PHP used 273312 bytes.
Before the function was finished we checked the memory usage again and it used 383520.
We checked the size of $content which is 110000 bytes.
273312 + 110000 = 383312
The remaining 208 bytes are from other variables (we only counted $content)
After the function was finished we checked the memory usage again and it was back to (almost (40 bytes difference)) the same as it was before.
The 40 bytes difference are likely to be function declarations and the for loop declaration.