SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot NevadaSam's Avatar
    Join Date
    May 2006
    Location
    Georgia
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Two Arrays in same FOREACH statement?

    I am trying to put a pull down select box on a form and I need to use two different arrays to echo the values so the HTML code will look like:
    <option value="01">January</option>
    <option value="12">December</option>


    This is what I have so far:

    PHP Code:
    <?php
    $monthValue 
    = array(1=>
    "01",
    "12");

    $monthName = array(2=>
    "January",
    "December");


    foreach (
    $monthValue as $monthValue => $monthList) {
            echo 
    "<option value=\"$monthList\"";
            echo 
    ">monthName</option>\n";
    }
    ?>
    How can I get the monthName in there?

    Sam
    ;

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code php:
    <?php
    $monthValue = array(1=>
    "01",
    "12");
     
    $monthName = array(2=>
    "January",
    "December");
     
     
    foreach ($monthValue as $i => $monthList) {
            echo "<option value=\"$monthList\"";
            echo ">{$monthName[$i]}</option>\n";
    }
    ?>
    or
    Code php:
    $months = array(
                    "01"=>"January",
                    "12"=>"December" );
     
     
    foreach ($months as $monthValue => $monthName) {
            echo "<option value=\"$monthValue\"";
            echo ">$monthName</option>\n";
    }
    ?>
    Saul

  3. #3
    SitePoint Zealot NevadaSam's Avatar
    Join Date
    May 2006
    Location
    Georgia
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was real quick. I like the second method best. I will study and learn it.

    Problem Solved!
    Thanks,
    Samantha


Bookmarks

Posting Permissions

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