Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.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 用其他数组替换从数组_Php_Arrays_Replace - Fatal编程技术网

Php 用其他数组替换从数组

Php 用其他数组替换从数组,php,arrays,replace,Php,Arrays,Replace,如何替换其他阵列中的阵列 我的代码: foreach($item_name[1] as $index => $text_to_draw) { $y_pos = $position_text_array[$index]; $color_text = $color_array[$index]; imagettftext($image, 10, 0, $x_pos, $y_pos, $color_text, $font, $text_to_draw); } 如果列表中有

如何替换其他阵列中的阵列

我的代码:

foreach($item_name[1] as $index => $text_to_draw) {
    $y_pos = $position_text_array[$index];
    $color_text = $color_array[$index];
    imagettftext($image, 10, 0, $x_pos, $y_pos, $color_text, $font, $text_to_draw);
}
如果列表中有数组,则需要替换
$text\u to\u draw
的结果:

$text_replace = array(
    "Nice" => "Bad",
    "Beautiful" => "Nice",
    "Fish" => "Dog",
    "Cat" => "Mouse",
);
我想要它像:

$text_to_draw = "Cat, Facebook, Fire";
那么输出应该是:

鼠标、Facebook、火

str\u replace()
接受数组:

$output = str_replace(array_keys($text_replace), $text_replace, $text_to_draw);
  • 搜索数组键
  • 替换为数组值
str\u replace()
接受数组:

$output = str_replace(array_keys($text_replace), $text_replace, $text_to_draw);
  • 搜索数组键
  • 替换为数组值