2014-02-10 28 views
0

以下代碼的輸出是什麼?打印迴應 - 意外回答

echo '1' . (print '2') + 3; 

我的答案是15,但得到的答覆是214

爲什麼?

+0

嗨,你可以給零下票,但請解釋爲什麼214來了 ?? –

+0

@marion非常感謝你:) –

+1

This [question](http://stackoverflow.com/questions/7094118/reference-comparing-phps-print-and-echo)也可以幫助 – Andy

回答

2

至於執行,該代碼會做:

print '2' -> outputs 2 
... print ALWAYS has a return value of 1, so the code becomes 

echo '1' . (1 + 3); // with output '2' 

這被簡化爲

echo '1' . 4; // with output '2' 
echo '14'; // output 2 

最終輸出:214

+0

哦,我明白了,謝謝非常 :) –