Jump to content

[SOLVED] .= ?? what is it exacly?


Foser

Recommended Posts

As we have already seen in the Echo Lesson, the period "." is used to add two strings together, or more technically, the period is the concatenation operator for strings.

 

PHP Code:

$a_string = "Hello";

$another_string = " Billy";

$new_string = $a_string . $another_string;

echo $new_string . "!";

 

Display:

Hello Billy!

 

link

http://www.tizag.com/phpT/operators.php

The .= operator is handy if you have a loop running and want to repeatedly add something onto the end of a string.

 

<?php
  $txt='';
  for ($i=0;$i<5;$i++) {
    $txt.='*';
  }
  echo $txt;
?>

 

The above is exactly the same as this:

 

<?php
  $txt='';
  for ($i=0;$i<5;$i++) {
    $txt=$txt.'*';
  }
  echo $txt;
?>

 

All the above does is make a string containing "*****" (five stars)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.