php替换数组里的字符串的方法:可以利用str_replace函数来进行替换,如【str_replace("red","pink",$arr,$i)】。如果搜索的字符串是一个数组,那么它将对数组中的每个元素进行查找和替换。
本文操作环境:windows10系统、php 7.3、thinkpad t480电脑。
如果我们需要替换数组中的字符串,可以利用str_replace()函数。
提示:如果搜索的字符串是一个数组,那么它将对数组中的每个元素进行查找和替换。
语法:
str_replace(find,replace,string,count)参数介绍:
find 必需。规定要查找的值。
replace 必需。规定替换 find 中的值的值。
string 必需。规定被搜索的字符串。
count 可选。一个变量,对替换数进行计数。
代码示例:
<!DOCTYPE html> <html> <body> <?php $arr = array("blue","red","green","yellow"); print_r(str_replace("red","pink",$arr,$i)); echo "<br>" . "Replacements: $i"; ?> <p>In this example, we search an array to find the value "red", and then we replace the value "red" with "pink".</p> </body> </html>(学习视频分享:php视频教程)
运行结果:
相关推荐:php教程
以上就是php如何替换数组里的字符串的详细内容!
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did52579
php如何替换数组里的字符串
阅读:50次