U PHP-u postoje dva operatora za rad sa stringovima:
Drugi operator dodaje operand sa desne strane operandu sa leve strane.
Primer:
<?php
$motori = "Ja volim ";
echo "\$motori = ", $motori, "<br>";
echo "\$plavi = \$motori . \"plavi\"<br>";
$plavi = $motori . "plavi ";
echo "motor \$plavi = ", $plavi, "<br>";
echo "\$plavi .= \"Suzuki.\"<br>";
$plavi .= "Suzuki.";
echo "motor \$plavi = ", $plavi, "<br>";
?>
Ovaj fajl sacuvajte kao operatori-za-stringove.php.
Rezultat:
$motori = Ja volim
$plavi = $motori . "plavi"
motor $plavi = Ja volim plavi
$plavi .= "Suzuki."
motor $plavi = Ja volim plavi Suzuki.
In PHP, there are two operators to work with strings:
The first operator connects the operands on the left and right side in a single string.
Another operator adds operand from the right to operand on the left.
Example:
<?php
$motobikes = "I love ";
echo "\$motobikes = ", $motobikes, "<br>";
echo "\$blue = \$motobikes . \"blue\"<br>";
$blue = $motobikes . "blue ";
echo "motobike \$blue = ", $blue, "<br>";
echo "\$blue .= \"Suzuki.\"<br>";
$blue .= "Suzuki.";
echo "motobike \$blue = ", $blue, "<br>";
?>
Save this file as operators-forstrings.php.
Result:
$motobikes = I love
$blue = $motobikes . "blue"
motobike $blue = I love blue
$blue .= "Suzuki."
motobike $blue = I love blue Suzuki.
- operator konkatenacije (.)
- operator spajanja i dodele (.=)
Prvi operator spaja operande sa leve i desne strane u jedan string.
Drugi operator dodaje operand sa desne strane operandu sa leve strane.
Primer:
<?php
$motori = "Ja volim ";
echo "\$motori = ", $motori, "<br>";
echo "\$plavi = \$motori . \"plavi\"<br>";
$plavi = $motori . "plavi ";
echo "motor \$plavi = ", $plavi, "<br>";
echo "\$plavi .= \"Suzuki.\"<br>";
$plavi .= "Suzuki.";
echo "motor \$plavi = ", $plavi, "<br>";
?>
Ovaj fajl sacuvajte kao operatori-za-stringove.php.
Rezultat:
$motori = Ja volim
$plavi = $motori . "plavi"
motor $plavi = Ja volim plavi
$plavi .= "Suzuki."
motor $plavi = Ja volim plavi Suzuki.
In PHP, there are two operators to work with strings:
- concatenation operator (.)
- concatenating assignment operator (. =)
The first operator connects the operands on the left and right side in a single string.
Another operator adds operand from the right to operand on the left.
Example:
<?php
$motobikes = "I love ";
echo "\$motobikes = ", $motobikes, "<br>";
echo "\$blue = \$motobikes . \"blue\"<br>";
$blue = $motobikes . "blue ";
echo "motobike \$blue = ", $blue, "<br>";
echo "\$blue .= \"Suzuki.\"<br>";
$blue .= "Suzuki.";
echo "motobike \$blue = ", $blue, "<br>";
?>
Save this file as operators-forstrings.php.
Result:
$motobikes = I love
$blue = $motobikes . "blue"
motobike $blue = I love blue
$blue .= "Suzuki."
motobike $blue = I love blue Suzuki.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.