开发者

PHP operator confusion (a beginner's question)

I'm trying to figure out so开发者_高级运维meone 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. See http://www.php.net/manual/en/language.operators.string.php.


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

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


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜