Re:[PHP-WIN] help in understanding string / integer concatenation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 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

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux