Replies To: implementing count method in php

Re: implementing count method in php

You are duplicating the counter variable. You already have $i, which represents the count. Why do you copy it over to $coun? You may as well just remove $coun altogether and return $i.

Using empty() to determine if an element is set skews your results, if your intent is really to return the number of set elements in an array. It will exclude elements set to values like the number 0, FALSE, empty arrays, empty strings, and of course NULL. An element set to any of these (except perhaps NULL, one might argue) should be considered a part of the count. - You'd do better to use isset()

But this function is ultimately unnecessary, as I am sure you already know, seeing as PHP already has a count() function built in. Unless of course your goal is to do some sort of manual filtering of what is counted.