I put a lot of time into writing guides that make tech easier to understand. If you found one useful, consider buying me a coffee ☕ — it’s a small way to say thanks and it motivates me to keep sharing.

Count Non-Empty Array Values

Counting the elements in an array is quite simple. The $counter variable will now contain the value of 3. However, if your array contains empty values like the following array it would still return 3. This of course would be problematic in some situations of your script. In order to get the accurate count, we…