This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
我实际上不知道如何描述我想要的东西,但我会告诉你:
例如:
$data1 = "the color is";
$data2 = "red";
Run Code Online (Sandbox Code Playgroud)
我应该做什么(或处理)所以$ result是$data1和$data2?的组合?
期望的结果:
$result = "the color is red";
Run Code Online (Sandbox Code Playgroud) 我想用一些字符串文字HTML回显PHP函数.
这就是我认为它的完成方式:
echo '<a href="' + $prevpost->url() + '" class="postnav left nextpost"></a>';
Run Code Online (Sandbox Code Playgroud)
......但是没有回报.我尝试了引号等的小变化但是我担心我正在咆哮错误的树,我无法真正找到我需要的搜索.
注意:echo $prevpost->url();在任何人询问是否有效之前,确实会返回我尝试链接的URL.
我有这段可以运行的 PHP 代码:
for ($i=0; $i < 5; $i++) {
do stuff to $class
echo "<i class=\"glyphicon glyphicon-star $class\"></i>";
}
Run Code Online (Sandbox Code Playgroud)
我如何将每次迭代附加到一个变量(例如),然后能够显示结果,而不是echo在循环中使用$stars
echo "$stars";
Run Code Online (Sandbox Code Playgroud)