<?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");
?>
欲望输出:
Due (Jan+Feb+Mar)
如何使用str_replace函数从数组中获取此输出?
答案 0 :(得分:0)
你需要这样吗?
$a = array('1'=>'Jan', '2'=>'Feb','3'=>'Mar');
$replaceStr = "";
foreach ($a as $months) {
$replaceStr[] = str_replace($months, "(Jan+Feb+Mar)", $months);
}
print_r($replaceStr);
答案 1 :(得分:0)
您可以尝试使用所需的输出。它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");