我想创建一个变量include_items
并继续为其添加字符串。
在PHP中它会......
$include_items = "<td>first item</td>";
$include_items .= "<td>second item</td>";
$include_items .= "<td>third item</td>";
答案 0 :(得分:7)
尝试<<
,看看它是如何运作的。您也可以使用+=
,但这会不必要地创建额外的对象。
答案 1 :(得分:6)
String
, +
is the concatenation operator,所以: +=
irb(main):001:0> foo = "asdf"
=> "asdf"
irb(main):002:0> foo += " and stuff"
=> "asdf and stuff"