PHP Foreach String Concatenation
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
wit开发者_如何学JAVAh 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")
);
}
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"));
}
精彩评论