PHP Foreach字符串连接

问题描述:

I'm attempting to modify some PHP to suit my needs and I'm having a bit of trouble.

I've created the variable $mutitag to hold the names of some variables from which I need to fetch some values.

I made a foreach loop to set $tv as each value of $multitag, fetch the values from the database, and return them into $get_tags. However, when I run the code below it only returns the values from the second value of $multitag array. How can I correctly concatenate $get_tags with all of the returned values? Thanks for your help!

$multitag = explode(",", $tv);
if ($tv == '' && !isset($value)) {
    return "No template variable for tags was declared.";
}

foreach ($multitag as $tv) {
    $get_tags = implode(
        $delimiter,
        $modx->getTemplateVarOutput($idname=array($tv), $page_id, $published="1")
    );
}

我正在尝试修改一些PHP以满足我的需求而且我遇到了一些麻烦。 p>

我创建了变量 $ mutitag code>来保存一些变量的名称,我需要从中获取一些值。 p>

我做了 foreach code>循环,将 $ tv code>设置为 $ multitag code>的每个值,获取 数据库中的值,并将它们返回到 $ get_tags code>。 但是,当我运行下面的代码时,它只返回 $ multitag code>数组的第二个值。 如何正确地将 $ get_tags code>与所有返回的值连接起来? 谢谢你的帮助! p>

  $ multitag = explode(“,”,$ tv); 
if($ tv ==''&&!isset($ value)){
 返回“没有声明标签的模板变量。”; 
} 
 
foreach($ multitag as $ tv){
 $ get_tags = implode(
 $ delimiter,
 $ modx-> getTemplateVarOutput($ idname)  = array($ tv),$ page_id,$ published =“1”)
); 
} 
  code>  pre> 
  div>

Concat the variable get_tags with .=

$get_tags = '';
//...
$get_tags .= implode(...);

$get_tags = '';

foreach($multitag as $tv){
   $get_tags .= implode($delimiter,$modx->getTemplateVarOutput($idname=array($tv), $page_id, $published="1"));
}