Thread: Array Help...

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

    Could someone please enlighten me?
    I am trying to display an associative array.
    The array has been created properly because
    the proper values are displayed with know
    keys. Why then does the following snip of
    code only display 1 array value when I know
    there are more?

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    do {
    list($value,$option) = each($employee_select);
    print "<option value="" . $value . "">" . $option . "</option>n";
    } while(next($employee_select));

    Could anyone post a nice little example of
    how to do this correctly?


  2. #2
  3. No Profile Picture
    rod k
    Devshed Newbie (0 - 499 posts)
    Well, I don't know why it's not working, but I do see a problem. each() and next() both advance the array pointer. If you only have two elements that would be why you have a problem.

    Instead of a do..while loop, just use a while.

    while (list($value,$option)=each($employee_select)
    print "<option value="$value">$option"<option>n";

Similar Threads

  1. sort: find duplicate string elements in array
    By sciencelife in forum Java Help
    Replies: 3
    Last Post: January 27th, 2004, 01:29 PM
  2. C++ programming help.
    By Programming1 in forum C Programming
    Replies: 1
    Last Post: January 20th, 2004, 10:47 AM
  3. another remove array values from an array
    By robee in forum PHP Development
    Replies: 6
    Last Post: November 20th, 2003, 12:09 AM
  4. multi dimensional arrays - Can't grasp how to?
    By Kaleina in forum PHP Development
    Replies: 17
    Last Post: November 5th, 2003, 03:18 PM
  5. problem with array
    By Geekoidxp in forum PHP Development
    Replies: 3
    Last Post: October 12th, 2003, 01:22 PM

IMN logo majestic logo threadwatch logo seochat tools logo