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);
- 搜索数组键
- 替换为数组值