christina
christina

Reputation: 661

PHP operator confusion (a beginner's question)

I'm trying to figure out someone else's code and have come across this piece of code:

            $html = '<div class="event">' . "\n";

        if (get ( 'Event_Image' ))
        {
        $html .= '<a href="' . get ( 'Event_Image' ) . '">'
        . '<img src="' . pt () . '?src=' . get ( 'Event_Image' ) . '&amp;w=100" alt="' . get_the_title () . '" />'
        . '</a><br />' . "\n";
        }

        $html .= '<a href="' . get_permalink ( $eventId ) . '">' . //  title="Permanent Link to ' . get_the_title_attribute() . '"
get_the_title () . '</a><br />' . "\n";

        if (get ( 'Event_Time' ))
        {
            $html .= get ( 'Event_Time' ) . '<br />' . "\n";
        }

        if (get ( 'Store_Location' ))
        {
            $html .= get ( 'Store_Location' );
        }

        $html .= '</div><!-- event -->' . "\n";

        $eventsArr [$dateArr] [$eventId] = $html;
    }

My question: What does the .= mean? Does it add to the variable (in this case $html)?

Upvotes: 1

Views: 171

Answers (5)

Gordon
Gordon

Reputation: 317039

It means concatenate/append the value on the right hand to the value stored in the variable:

$a  = 'str';
$a .= 'ing';
echo $a; // string

Upvotes: 3

Sarfraz
Sarfraz

Reputation: 382776

Yes, you got it right, here is an example:

$str  = 'Hello ';
$str .= 'World';
echo $str;

Result:

Hello World

Upvotes: 2

Daniel A. White
Daniel A. White

Reputation: 190952

It is concatenate, then assign.

Same as:

$html = $html . $someString;

Upvotes: 1

Peter O&#39;Callaghan
Peter O&#39;Callaghan

Reputation: 6186

It means concatinate equals. So

$var = 'foo';
$var .= 'bar';

echo $var;
// output is 'foobar'

Upvotes: 1

Related Questions