从PHP中的函数回显多个字符串

从PHP中的函数回显多个字符串

问题描述:

I have tried to create a function that will take two arguments and in theory, echo out the result. After doing some Googling, I got the impression that this should be accomplished using an array, however I'm not too sure on the logic.

I was hoping I could call the function like so - kb_article("How to do something", "Q12345"), to get the formatting of:

Related KB Article(s):
How to do something - Q12345

    function kb_article($title, $code)
{
    echo "<h2>Related KB Article(s): </h2><br />";
    echo $title + " - " + $code;
}

How can this be achieved?

我试图创建一个带有两个参数的函数,理论上,它会回显结果。 在做了一些谷歌搜索之后,我得到的印象是应该使用数组来完成,但是我对逻辑不太确定。 p>

我希望我能像这样调用函数 - kb_article(“如何做某事”,“Q12345”),获取格式: p>

相关知识库文章:
怎么做 某事 - Q12345 p> blockquote>

  function kb_article($ title,$ code)
 {
 echo“&lt; h2&gt;相关知识库文章:  &lt; / h2&gt;&lt; br /&gt;“; 
 echo $ title +” - “+ $ code; 
} 
  code>  pre> 
 
 

这怎么可以 实现了? p> div>

String concatenation is performed using . ( instead of + ). Here's the corrected version of your function:

function kb_article($title, $code)
{
    echo '<h2>Related KB Article(s):</h2><br />';
    echo $title . " - " . $code;
}

You can just enclose the whole string in double quotes...

function kb_article($title, $code)
{
    echo "<h2>Related KB Article(s): </h2><br />";
    echo "$title  -  $code";
}

kb_article("title","code");

// outputs the expected title - code

Or as previously posted, do string concatenation properly.

function kb_article($title, $code)
{
    echo "<h2>Related KB Article(s): </h2><br />";
    echo  $title . " - " . $code;
}

kb_article("title","code");

You need to use . instead of + to concatenate in php. Like so:

echo $title." - ".$code;