Re:help in understanding string / integer concatenation
| From: | Mihai Frisan | Date: | Wed, 12 Jan 2005 07:14:02 +0000 |
| Subject: | Re:help in understanding string / integer concatenation | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-25291@lists.php.net to get a copy of this message | ||
that's what you need:
$str = 'hello "' . ($i+1) . '"';
you must put $i+i in brachets in order to evaluate first the expresion
$i+1 and then concatenates it to the string
best regards
mihai
i'm not young enough to know everything
Hello all;
I am a new PHP user. (But not new at programing.) I'm
running Win XP, Apache, PHP 5.0.3 (and PostgreSQL 8,
not that that should make a difference).
I'm trying to use PHP to generate drop down lists of
arbitrary length in a form (<select> and <option>)
I've come across something strange, to me, in using the
concatenation (.) operator. A simplified piece of code
follows. My question is, why is the output different
between the two versions?
apologies if I've missed something in the list archives.
Thanks in advance.
Ray
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?PHP
$i=4;
$str = 'hello "' . $i+1 . '"';
echo $str;
?>
</body>
</html>
output:
--------------------
1"
or, version 2, same as above except break
$str = 'hello "' . $i+1 . '"';
into
$str = 'hello "';
$str .= $i+1 . '"';
output becomes:
--------------------
hello "5" (this is what I want to see)
IE vs. netscape makes no difference.
-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php