Re: Know any slick ways to build a string from array?
From: Gary L. Burnore (gburnore_at_databasix.com)
Date: 09/24/04
- Previous message: R. Rajesh Jeba Anbiah: "PHP-4 to PHP-5 Conversion"
- In reply to: Geoff Berrow: "Re: Know any slick ways to build a string from array?"
- Next in thread: Geoff Berrow: "Re: Know any slick ways to build a string from array?"
- Reply: Geoff Berrow: "Re: Know any slick ways to build a string from array?"
- Reply: Geoff Berrow: "Re: Know any slick ways to build a string from array?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
===========================================================================
- Previous message: R. Rajesh Jeba Anbiah: "PHP-4 to PHP-5 Conversion"
- In reply to: Geoff Berrow: "Re: Know any slick ways to build a string from array?"
- Next in thread: Geoff Berrow: "Re: Know any slick ways to build a string from array?"
- Reply: Geoff Berrow: "Re: Know any slick ways to build a string from array?"
- Reply: Geoff Berrow: "Re: Know any slick ways to build a string from array?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|