1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Athens, GA
    Rep Power
    Quickie Topic:
    Sometimes, I want to know how many elements are really in an array (php3).

    The count() and sizeof() functions apparently return the number of non-empty array elements, and if you do a while loop checking for empty will stop on the first empty element.

    I have been using the following function:
    function truecount($theArray) {
    if (is_array($theArray)) {
    return key($theArray);

    but if the key is non-numeric, won't that trip me up?

    Anyone have a better solution?
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Niagara Falls (On the wrong side of the gorge)
    Rep Power
    Yes, it will, but then again if the index is associative, count() will always return the correct number of elements. IOW, you can't "skip" an element in an associative array.

Similar Threads

  1. generating random numbers of a fixed length
    By alexh in forum PHP Development
    Replies: 3
    Last Post: June 24th, 2004, 03:22 AM
  2. user authentication and real player files
    By kyawkyaw in forum PHP Development
    Replies: 0
    Last Post: February 12th, 2004, 10:32 PM
  3. C language, arrays and functions
    By jenny79 in forum C Programming
    Replies: 2
    Last Post: November 18th, 2003, 07:09 AM
  4. finding max string length if more than 2 elements
    By sri197 in forum XML Programming
    Replies: 1
    Last Post: November 7th, 2003, 06:17 PM
  5. Replies: 8
    Last Post: October 25th, 2003, 09:27 PM

IMN logo majestic logo threadwatch logo seochat tools logo