如何从其他阵列替换数组?
我的代码:
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_to_draw
的结果:
$text_replace = array(
"Nice" => "Bad",
"Beautiful" => "Nice",
"Fish" => "Dog",
"Cat" => "Mouse",
);
我想要它:
$text_to_draw = "Cat, Facebook, Fire";
然后输出应为:
鼠标,Facebook,Fire
答案 0 :(得分:0)
str_replace()
接受数组:
$output = str_replace(array_keys($text_replace), $text_replace, $text_to_draw);