简体   繁体   中英

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 )?

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

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

Result:

Hello World

It means concatinate equals. So

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

echo $var;
// output is 'foobar'

It is concatenate, then assign.

Same as:

$html = $html . $someString;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM