<?php
$a=array('1'=>'Jan', '2'=>'Feb','3'=>'Mar');
print_r($a);
$str ="<p>Due Month</p>";
echo str_replace("Month","(Jan+Feb+Mar)","Due Month");
?>
Desire Output: Due (Jan+Feb+Mar)
How can I get this output from array using str_replace function?
You can try it for your desired output. It works 100%
$a = array('1'=>'Jan', '2'=>'Feb','3'=>'Mar');
print_r($a);
$comma_separated = implode("+", $a);
$str ="<p>Due Month</p>";
echo str_replace("Month","$comma_separated","Due Month");
Do you need like this?
$a = array('1'=>'Jan', '2'=>'Feb','3'=>'Mar');
$replaceStr = "";
foreach ($a as $months) {
$replaceStr[] = str_replace($months, "(Jan+Feb+Mar)", $months);
}
print_r($replaceStr);