Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    48
    Thanks
    1
    Thanked 1 Time in 1 Post

    FOREACH two arrays in the one 'foreach' function?

    Hi I need to figure out how to do the following:

    I need to use two arrays to output two sets of variables into my website's echo content:

    CODE:

    PHP Code:
    <?
    $giftCertificates 
    = array("gift-certs-funny_0002""gift-certs-funny_0003""gift-certs-funny_0004"); /*ARRAY 1*/
    $products = array("funny (2)""funny (3)""funny (4)"/*ARRAY 2*/


    foreach ($giftCertificates as $key=>$details
    /*HOW DO I ADD IN THE SECOND ARRAY SO I CAN PUT $PRODUCTS IN THE SAME 'FOREACH' AS THE
    $giftCertificates
    */
    {
        echo 
    "<div id='certificate".$key."'>\n";
        echo 
    "<div class='lefthandpanel'>\n";
        echo 
    " <img src='images/certificates/".$details.".jpg'>\n";
        echo 
    "</div>\n";
        echo 
    "<div class='righthandpanel'>\n";

        
        echo 
    " <div class='shopEntry'>\n";
        echo 
    "  <h3>A Gift Certificate from Mylastrequest.ie</h3>\n";
        echo 
    "    <p>A personalised Gift Certificate from My Last Request and a Subscription to the website.</p>\n";
        
    /*THIS IS WHERE I WANT THE SECOND ARRAY TO GO*/
    echo "    <p>Includes Free Updates 24/7<br>Product Code:$prod </p>\n";
    /*THIS IS WHERE I WANT THE SECOND ARRAY TO GO*/
        
    echo "    <form action='https://www.paypal.com/cgi-bin/webscr' method='post'>";
        echo 
    "    <input type='hidden' name='cmd' value='_s-xclick'>";
        echo 
    "    <input type='hidden' name='hosted_button_id' value='8777643'>";
            echo 
    "       <table>";
            echo 
    "       <tr><td><input type='hidden' name='on0' value='Subscription Type'>Subscription Type</td></tr><tr><td><select name='os0'>";
        echo 
    "       <option value='1 Year'>1 Year €19.99";
        echo 
    "                <option value='3 Years'>3 Years €29.99";
        echo 
    "                <option value='Life Time'>Life Time €49.99";
        echo 
    "        </select> </td></tr>";
        echo 
    "        </table>";
            echo 
    "                <input type='hidden' name='currency_code' value='EUR'>";
            echo 
    "                <input type='image' src='https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'>";
            echo 
    "                <img border='0' src='https://www.paypal.com/en_US/i/scr/pixel.gif' width='1' height='1'>";
            echo 
    "                </form>";
        echo 
    " </div>\n";
        echo 
    " </div>\n";
        echo 
    " <br clear='all'>\n";
        echo 
    "</div>\n";
        echo 
    "<p>&nbsp;</p>\n";

    }

    ?>

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Location
    somewhere over the rainbow
    Posts
    105
    Thanks
    2
    Thanked 14 Times in 14 Posts
    something like that?
    PHP Code:
    <?php
    $giftCertificates 
    = array("gift-certs-funny_0002""gift-certs-funny_0003""gift-certs-funny_0004"); /*ARRAY 1*/
    $products = array("funny (2)""funny (3)""funny (4)"); /*ARRAY 2*/


    foreach ($giftCertificates as $key=>$details
    /*HOW DO I ADD IN THE SECOND ARRAY SO I CAN PUT $PRODUCTS IN THE SAME 'FOREACH' AS THE
    $giftCertificates
    */
    {
        
        
        echo 
    "<div id='certificate".$key."'>\n";
        echo 
    "<div class='lefthandpanel'>\n";
        echo 
    " <img src='images/certificates/".$details.".jpg'>\n";
        echo 
    "</div>\n";
        echo 
    "<div class='righthandpanel'>\n";

        
        echo 
    " <div class='shopEntry'>\n";
        echo 
    "  <h3>A Gift Certificate from Mylastrequest.ie</h3>\n";
        echo 
    "    <p>A personalised Gift Certificate from My Last Request and a Subscription to the website.</p>\n";
        echo 
    '<b>'.$products[$key].$details.'</b>';
    echo 
    "    <p>Includes Free Updates 24/7<br>Product Code:$prod </p>\n";
        echo 
    '<b>'.$products[$key].$details.'</b>';
        echo 
    "    <form action='https://www.paypal.com/cgi-bin/webscr' method='post'>";
        echo 
    "    <input type='hidden' name='cmd' value='_s-xclick'>";
        echo 
    "    <input type='hidden' name='hosted_button_id' value='8777643'>";
            echo 
    "       <table>";
            echo 
    "       <tr><td><input type='hidden' name='on0' value='Subscription Type'>Subscription Type</td></tr><tr><td><select name='os0'>";
        echo 
    "       <option value='1 Year'>1 Year €19.99";
        echo 
    "                <option value='3 Years'>3 Years €29.99";
        echo 
    "                <option value='Life Time'>Life Time €49.99";
        echo 
    "        </select> </td></tr>";
        echo 
    "        </table>";
            echo 
    "                <input type='hidden' name='currency_code' value='EUR'>";
            echo 
    "                <input type='image' src='https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'>";
            echo 
    "                <img border='0' src='https://www.paypal.com/en_US/i/scr/pixel.gif' width='1' height='1'>";
            echo 
    "                </form>";
        echo 
    " </div>\n";
        echo 
    " </div>\n";
        echo 
    " <br clear='all'>\n";
        echo 
    "</div>\n";
        echo 
    "<p>&nbsp;</p>\n";

    }



    /*
    for ($i=0; $i<=20; $i++)
    {
        $new_time = time() + (9 * 60 * 60);
        $fp = fopen("chatdata.txt", "w");
        if (flock($fp, LOCK_EX)) { // do an exclusive lock
            ftruncate($fp, 0);  // truncate file
            fwrite($fp,  '0'.$new_time.' <ajax-user> testing '.$i.'¿END');
            flock($fp, LOCK_UN); // release the lock
        } else {
            echo "error: Couldn't get the lock!";
        }
        fclose($fp);
        usleep(200000); //1000000 = 1 second  
    }
    */
    //http://www.fresh.co.il/dcforum/SiteBuilding/7667.html

    /*
    //echo str_repeat(" ",300);
    ignore_user_abort(true); //this way, the user can stop the output, but not the script.
    $i=0;
    echo ".";
    while ($i<=20 && connection_status()==0) {
            $i++;
             echo ".";
             flush();
             sleep(5);
             

    }
    //echo str_repeat("1",300);
             $new_time = time() + (9 * 60 * 60);
             if (connection_status()!=0){
                     report($new_time, 'disz');
                     die(); //kills the script
             }
             if (connection_aborted()) {
                report($new_time, 'disz2');
            }


    function report($page_time ,$msg) //(current time, message)
    // write a new msg to chatdata
    {
        $fp = fopen("chatdata.txt", "w");
        if (flock($fp, LOCK_EX)) { // do an exclusive lock
            ftruncate($fp, 0);  // truncate file
            fwrite($fp,  $page_time.' '.$msg.'¿END');
            flock($fp, LOCK_UN); // release the lock
        }
        fclose($fp);    
    }

    */

    /*
    for ($i=0; $i<=255; $i++)
    {
        echo 'chr('.$i.') = ' . chr($i) . "<br />\n\r";
    }

    */
    /*
    session_start();
    echo $_SESSION['online']."<br>";


    //session_unregister('online');
    unset($_SESSION['online']);

    if(isset($_SESSION['online']))
        echo 'set';
    else
        echo 'not set';
    */





    /*
        $message=1;

        //connect to db
        $link = mysql_connect("mysql4.freehostia.com","erannn_db","1845")
        or die("Could not connect: " . mysql_error());
        mysql_select_db("erannn_db");

        //make a query
        $q = mysql_query("SELECT * FROM `chatlog` where id<=$message ORDER BY `id` DESC LIMIT 0,50") or die(mysql_error());
        if ($q) {
        while($a = mysql_fetch_array($q))
        {
            $message = '@'.$a['msg'];
        }}

        // And send the message to the user
        echo $message; 
    */

    /*
        $page_time = time();
        $msg = 'msg';
     
        include("conn.php");
        mysql_query("insert into chatlog (post_time, nick, msg) values('$page_time', 'ajax-user', '$msg');");
        echo 'mo0';
    */

    /*
    To do list:
    * users: to get them on the start
    * topic
    * names
    * log? / db?
    * timing
    * lag: page time and php time
    * more info to the output and more to the txt.



    */


    ?>
    you could also do a for loop and catch the current elements as i did..
    :. -= | Eran | =- .:
    __________________


  •  

    Posting Permissions

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