Which is a better way to check if an array has more than one element?
arrays, php
Solution
Use this
if (sizeof($arr) > 1) {
....
}
Or
if (count($arr) > 1) {
....
}
`sizeof()` is an alias for `count()`, they work the same.
Edit: Answering the second part of the question: The two lines of code in the question are not alternative methods, they perform different functions. The first checks if the value at `$arr['1']` is set, while the second returns the number of elements in the array.
Problem
I just need to check if an array has more than one element. I am trying to do it this way : ``` if (isset($arr['1'])) ``` the other traditional way is ``` if (sizeof($arr)>1) ``` Which of the two is better? In such situaions, how should I judge between two alternate methods? Is there any performance check meter available to measure which is better?