note 63741 added to language.operators.string
| From: | caliban at darklock dot com | Date: | Wed, 29 Mar 2006 19:10:42 +0000 |
| Subject: | note 63741 added to language.operators.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106967@lists.php.net to get a copy of this message | ||
WRT Stephen's note:
My example of concatenation and array methods of string building does not include the interstitial
logic, which is expected to include conditionals.
Concatenation method:
$str="This is my list";
if($list=="o") $str.="<ol>";
else $str.="<ul>";
foreach($item as $i) $str.="<li>$i</li>";
if($list=="o") $str.="</ol>";
else $str.="</ul>";
Array method:
$str=array("This is my list");
if($list=="o") $str[]="<ol>";
else $str[]="<ul>";
foreach($item as $i) $str[]="<li>$i</li>";
if($list=="o") $str[]="</ol>";
else $str[]="</ul>";
$str=implode("",$str);
You can't do either of these with a single double-quoted string. However, if what you are doing
CAN be done in a single double-quoted string, Stephen is completely correct in observing that you
should do that instead of concatenating.
----
Server IP: 66.163.161.117
Probable Submitter: 71.37.45.156
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.operators.string.php
Edit -- http://master.php.net/note/edit/63741
Del: integrated -- http://master.php.net/note/delete/63741/integrated
Del: useless -- http://master.php.net/note/delete/63741/useless
Del: bad code -- http://master.php.net/note/delete/63741/bad+code
Del: spam -- http://master.php.net/note/delete/63741/spam
Del: non-english -- http://master.php.net/note/delete/63741/non-english
Del: in docs -- http://master.php.net/note/delete/63741/in+docs
Del: other reasons-- http://master.php.net/note/delete/63741
Reject -- http://master.php.net/note/reject/63741
Search -- http://master.php.net/manage/user-notes.php