Mann Mann - 28 days ago 7
PHP Question

Loop through condition and append to string in php?

Am writing some content to a file, I store all the content in a variable. Some parts of the file content need to be repeated with some minor changes, those changes are stored in a variable and I need to run a for loop for that change.

See the following code sample,

$looped_valueArray; //this is an array i need to loop the content in $looped_value
//to show all the values
$content = 'sample content '. $looped_value.'
fdgdf';


I could not loop write a
forloop
appending to a string like

$content = 'sample content '.
foreach($looped_valueArray as $looped_value) $looped_value;.'fdgdf';

Answer

Hi follow this scripts if you would like append your content in a variable:

$content ="sample content ";
foreach($looped_valueArray as $looped_value){
$content .=$looped_value;

}
Comments