phpc.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A server for PHP programmers & friends. Join us for discussions on the PHP programming language, frameworks, packages, tools, open source, tech, life, and more.

Administered by:

Server stats:

800
active users

@davidbisset looks costly on CPU though. Could be useful in long running scripts

@davidbisset Now I want to try the example but set the element to null before unsetting it... 🤔

@davidbisset Nope assigning it to null doesn't help.

However, if your array is more than just allocated but has actual values in each element. Say a long string... unsetting it DOES reduce the memory usage.

I modified the example to add a step which assigns each element:

str_repeat("abcdefg", 100);

And memory use went up of course. But then after unsetting each element it does drop the memory back down. So unsetting array elements is worth it.

@omerida @syntaxseed Like I said, learned something. And thanks for the extra info too.