Re: Know any slick ways to build a string from array?

From: Gary L. Burnore (gburnore_at_databasix.com)
Date: 09/24/04

  • Next message: R. Rajesh Jeba Anbiah: "Re: html output getting garbled"
    Date: Fri, 24 Sep 2004 09:03:09 -0400
    
    

    On Fri, 24 Sep 2004 13:39:53 +0100, Geoff Berrow
    <blthecat@ckdog.co.uk> wrote:

    >I noticed that Message-ID:
    ><29cee28.0409210102.620134bb@posting.google.com> from harryman100
    >contained the following:
    >
    >>$string = "";
    >>foreach ($months AS $key => $month) {
    >> $string .= "<option value=\"$key\">$month</option>\n";
    >>}
    >
    >Slick, but I prefer this (untested)..
    >
    >
    >$string = "<select name="month">";
    >foreach ($months AS $key => $month) {
    > if($key==$k){$selected="selected";} else{$selected="";}
    > $string .= "<option value=\"$key\" $selected>$month</option>\n";
    >}
    >$string.="</select>";

    Is one str_replace faster than 12 if's? If so, then:

    $string = "<select name="month">";

    foreach ($months AS $key => $month) {
        $string .= "<option value=\"$key\" $selected>$month</option>\n";
    }

    $string.="</select>";

    if(isset($_POST['month']) {
       $k=$_POST['month'];
       $string = str_replace("\$k\">","\"$k\" selected>", $string);
    }

    -- 
    gburnore@databasix dot com          
    ---------------------------------------------------------------------------
                      How you look depends on where you go.
    ---------------------------------------------------------------------------
    Gary L. Burnore                       |  ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
                                          |  ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
    DataBasix                             |  ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
                                          |  ÝÛ³ 3 4 1 4 2  ݳ޳ 6 9 0 6 9 ÝÛ³
    Black Helicopter Repair Svcs Division |     Official Proof of Purchase
    ===========================================================================
          Want one?  GET one!   http://signup.databasix.com
    ===========================================================================
    

  • Next message: R. Rajesh Jeba Anbiah: "Re: html output getting garbled"

    Relevant Pages

    • Re: Any girls?
      ... >> Five Cats ... -- gburnore@databasix dot com ... Black Helicopter Repair Svcs Division | Official Proof of Purchase ...
      (comp.lang.php)
    • Re: is it ok to post job vacancy?
      ... No. That's what the .jobs groups are for. ... gburnore@databasix dot com ... Black Helicopter Repair Svcs Division | ... Official Proof of Purchase ...
      (comp.lang.php)
    • Re: How to get a row count from a PHP/MYQSL db search
      ... -- gburnore@databasix dot com ... Black Helicopter Repair Svcs Division | Official Proof of Purchase ...
      (comp.lang.php)
    • Re: is it ok to post job vacancy?
      ... -- gburnore@databasix dot com ... Black Helicopter Repair Svcs Division | Official Proof of Purchase ...
      (comp.lang.php)
    • Re: Windows XP CD
      ... to contact the Manufacture to get a copy of the OS media. ... >> this way you will be legal and not have to purchase a 2nd copy of the OS ... >> Grp at t k s o l dot c o m ...
      (microsoft.public.windowsxp.general)