PHP: Fastest way to check if an array is empty
March 9th, 2012
No comments
I just posted benchmarks for checking for an empty string that I ran when looking to improve the efficiency of an application. Another simple benchmark I ran was for ways to check if an array is empty.
Like strings, there are a ton of ways to check if am array is empty. These here are not exhaustive, but a few that I chose to test:
- !$array
- $array == false
- empty($array)
- count($array) == 0
- $array == array()
Categories: PHP