|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
W PHP są dwa operatory operujące na łańcuchach znaków (stringach). Pierwszym
z nich jest operator konkatenacji (połączenia) ('.'), który zwraca łańcuch
będący połączeniem zawartości lewego i prawego operandu. Drugim z nich jest
operator przypisania konkatenacyjnego ('.='), który dołącza zawartość
wyrażenia stojacego z prawej strony do zmiennej stojacej z lewej strony.
Zobacz także Operatory Przypisania.
User Contributed NotesStephen Clay
23-Dec-2005 04:10
<?php
"{$str1}{$str2}{$str3}"; $str1. $str2. $str3; ?>
Use double quotes to concat more than two strings instead of multiple '.' operators. PHP is forced to re-concatenate with every '.' operator.
caliban at darklock dot com
15-Dec-2004 04:57
String concatenation is faster than the array method:
$str="";
$str.="Some string";
$str.="Some other string";
...
$str.="The last string";
That runs roughly twice as fast as:
$str=array();
$str[]="Some string";
$str[]="Some other string";
...
$str[]="The last string";
$str=implode("",$str);
Not that I think this is a terribly widespread practice, but I've got an awful lot of legacy code with this array method in it and a comment to the effect that it's faster than string concatenation. Testing has shown the exact opposite, so I figured I'd enlighten anyone else with this misconception.
anders dot benke at telia dot com
27-Apr-2004 06:53
A word of caution - the dot operator has the same precedence as + and -, which can yield unexpected results.
Example:
<php
$var = 3;
echo "Result: " . $var + 3;
?>
The above will print out "3" instead of "Result: 6", since first the string "Result3" is created and this is then added to 3 yielding 3, non-empty non-numeric strings being converted to 0.
To print "Result: 6", use parantheses to alter precedence:
<php
$var = 3;
echo "Result: " . ($var + 3);
?>
php dot net at rinner dot at
20-Feb-2001 02:00
|