Linked Questions
10 questions linked to/from Checking for empty arrays: count vs empty
643 votes
18 answers
1.3m views
How to check whether an array is empty using PHP?
players will either be empty or a comma separated list (or a single value). What is the easiest way to check if it's empty? I'm assuming I can do so as soon as I fetch the $gameresult array into $...
393 votes
20 answers
495k views
PHP - Check if two arrays are equal
I'd like to check if two arrays are equal. I mean: same size, same index, same values. How can I do that? Using !== as suggested by a user, I expect that the following would print enter if at least ...
141 votes
5 answers
242k views
Multiple inputs with same name through POST in php
Is it possible to get multiple inputs of the same name to post and then access them from PHP? The idea is this: I have a form that allows the entry of an indefinite number of physical addresses along ...
94 votes
5 answers
88k views
Recursive function to generate multidimensional array from database result
I'm looking to write a function that takes an array of pages/categories (from a flat database result) and generates an array of nested page/category items based on the parent ids. I would like to do ...
114 votes
3 answers
18k views
Is PHP's count() function O(1) or O(n) for arrays?
Does count() really count the all the elements of a PHP array, or is this value cached somewhere and just gets retrieved?
19 votes
4 answers
11k views
Why count(false) return 1?
Do you know why <?= count(false) ?> returns 1?
10 votes
2 answers
6k views
Best way to check if PHP Array is empty [closed]
This is mostly superficial but what's the best (faster performing, not personal preference or readability) way to check if an array is empty: count($arr) == 0 empty($arr) $arr === array() Other? My ...
0 votes
3 answers
369 views
Easiest way to check if PHP array is not empty [closed]
How do I check that a PHP array is not empty? // If $columns array is not empty... foreach ($columns as $column) { echo $column; }
-2 votes
7 answers
86 views
Is this the correct way of checking empty array?
I want to check if array is empty or not, i wrote few lines of code for it if(array() == $myArray){ echo "Array"; } or if(array() === $myArray){ echo "Array"; } I'm confused which one to use, ...
-2 votes
3 answers
144 views
My array is not empty but empty() claims it is [closed]
I've var dumped my array: array(4) { [0]=> string(72) " 1 " [1]=> string(57) " 2 " [2]=> string(63) " › " [3]=> string(63) " » " } When I check: empty($myArray); It always says true. Why ...