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

    Join Date
    Jul 2000
    Posts
    9
    Rep Power
    0
    Hi,
    I have an array that contains info on my sites members:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $original = array(
    "reaper" => "Reaper's info.",
    "zombie" => "Zombie's info."
    );
    [/code]

    Now that is fine and it works fine, but I need to be able to display all the contents of an array.
    A C++ programmer friend of mine told me to use a For loop, so I came up with this:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    if ($member == "all") {
    for ($i = 1; $i <= 6; $i++) {
    echo $original[$i];
    }
    [/code]

    But the problem is, the only way to make this work is if the keys in the array are numerical - but I shall be using the same type of code for other arrays that shall have new members' info placed on them without any manual intervention, and the keys need to be the members' usernames.

    So what it comes down to is I need to be able to display all the contents of an array, and BTW the server my host is using only supports PHP3.

    Hopefully someone will be able to make sense of this and help me.
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    You need to use an while..each construct.

    while(list($mem_name,$mem_info)=each($original))
    {
    // $mem_name has current members name
    // $mem_info has current members info
    }
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    9
    Rep Power
    0
    I tried that but couldn't get it to work.

    I was thinking maybe there was around my problem and I think I have one.

    What I could do is sort the array alphabeticaly by the keys then have the key names turned to numbers.

    Is there anyway to do that automatically? But the original key values would need to be kept so when a new member joins the array could be sorted taking the new member into account.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    59
    Rep Power
    15
    You might be able to use array_walk, I am not sure of the exact syntax, you'll have to look it up on www.php.net

    Chris
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    9
    Rep Power
    0
    I tried array_walk and it works a treat, thanks for the help.

Similar Threads

  1. arrays within arrays - looping through
    By kolatracks in forum PHP Development
    Replies: 2
    Last Post: February 1st, 2004, 03:16 AM
  2. Check Boxes, Arrays, and Loops
    By gjb79 in forum PHP Development
    Replies: 5
    Last Post: December 2nd, 2003, 07:34 PM
  3. For loops and arrays
    By Bozpw in forum PHP Development
    Replies: 3
    Last Post: September 19th, 2002, 03:15 AM
  4. How do you pass functions via arrays into loops?
    By rhymm in forum PHP Development
    Replies: 3
    Last Post: March 5th, 2002, 03:51 PM
  5. *Please* Help with loops, arrays, ducument.write.
    By kenezmn in forum HTML Programming
    Replies: 0
    Last Post: November 28th, 1999, 05:18 PM

IMN logo majestic logo threadwatch logo seochat tools logo