php - str_replace() 与关联数组

标签 php

您可以使用带有 str_replace() 的数组:

$array_from = array ('from1', 'from2'); 
$array_to = array ('to1', 'to2');

$text = str_replace ($array_from, $array_to, $text);

但是如果你有关联数组呢?

$array_from_to = array (
 'from1' => 'to1';
 'from2' => 'to2';
);

如何将它与 str_replace() 一起使用?
速度很重要——阵列足够大。

最佳答案

$text = strtr($text, $array_from_to)

顺便说一句,那仍然是一个一维“数组”。

关于php - str_replace() 与关联数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2399286/

相关文章:

php - Laravel - 在多对多关系中渴望加载单个项目

php - 我怎样才能在下拉列表中显示 2 列?

php - 有没有办法让ajax请求始终按顺序进行?

php - MYSQL查询每小时

PHP Json 编码数组

php - Magento 1.7 无法编辑某些产品

php - 我收到的 paypal token 无效?

php - 我可以在我的网站上创建一个按钮来备份我的数据库吗?

php - 通过 Auth Controller 保护 Assets /媒体文件夹?拉维尔 5.2

php - 使用 codeigniter 在 mysql 中连接