Results 1 to 3 of 3

Thread: [RESOLVED] Count Multidimensional Arary Items

  1. #1

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Resolved [RESOLVED] Count Multidimensional Arary Items

    I've created an array with the below format.

    $UserDetails[0][0]
    $UserDetails[1][0]
    $UserDetails[2][0]

    $UserDetails[0][1]
    $UserDetails[1][1]
    $UserDetails[2][1]


    I need to loop through the array but count($UserDetails) returns 3 which seems incorrect as there are only 2 "items" in the array that contains 3 values each. How can I get the number of "items" (in this case 2)?


    EDIT: If it makes a difference I'm declaring $UserDetails as a gloabl array.
    PHP Code:
    $GLOBALS['UserDetails'] = $UserDetails//make available in another function

    //Then to call it in another function
    global $UserDetails
    Last edited by lintz; Feb 27th, 2006 at 08:02 PM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Count Multidimensional Arary Items

    You have the dimensions the wrong way around. It should be:
    $UserDetails[0][0]
    $UserDetails[0][1]
    $UserDetails[0][2]

    $UserDetails[0][0]
    $UserDetails[0][1]
    $UserDetails[0][2]
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Count Multidimensional Arary Items

    Thanks VisualAd.

    Changed my dimensions but now when I attempt to show an item in the array it returns Array[1] or Array[2] etc...?

    PHP Code:
    global $UserDetails;
    $items count($UserDetails);
    echo 
    "items = $items<p>"//Shows 2 which is correct
    echo "Array Item - $UserDetails[1][1]"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width