如何将数组转换为字符串PHP?
要将数组转换为字符串,请使用PHP中的implode()概念。假设以下是我们的数组-
$sentence = array('My','Name','is','John');
要将上面的数组转换为字符串-
,implode(" ",$sentence)
示例
<!DOCTYPE html> <html> <body> <?php $sentence = array('My','Name','is','John'); echo "The string is=",implode(" ",$sentence); ?> </body> </html>
输出结果
The string is = My Name is John
现在让我们看看另一个PHP代码,其中我们还将添加分隔符-
示例
<!DOCTYPE html> <html> <body> <?php $sentence = array('One','Two','Three'); echo "The string is=",implode("*",$sentence); ?> </body> </html>
输出结果
The string is = One*Two*Three