Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php str_replace()字符串到数组错误_Php_Arrays - Fatal编程技术网

php str_replace()字符串到数组错误

php str_replace()字符串到数组错误,php,arrays,Php,Arrays,我对$search字符串和$replace字符串没有问题 但是如何将str_replace()与$search string和$replace array一起使用?提供了一个清晰的示例,说明如何使用数组(大小相同): 使用$search作为字符串和$replaces作为数组是不可能的,而且“奇怪”:应该使用哪个数组值进行匹配?什么意思$search string和$replace array??谢谢,我明白你的意思了 str_replace($search, $replace, $subject

我对$search字符串和$replace字符串没有问题

但是如何将
str_replace()
与$search string和$replace array一起使用?

提供了一个清晰的示例,说明如何使用数组(大小相同):


使用
$search
作为字符串和
$replaces
作为数组是不可能的,而且“奇怪”:应该使用哪个数组值进行匹配?

什么意思
$search string和$replace array?
?谢谢,我明白你的意思了
str_replace($search, $replace, $subject);
// Provides: You should eat pizza, beer, and ice cream every day
$phrase  = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy   = array("pizza", "beer", "ice cream");

$newphrase = str_replace($healthy, $yummy, $phrase);