如何将 PHP 数组转换为字符串?
phpserver side programmingprogramming更新于 2025/4/13 6:22:17
要将数组转换为字符串,请使用 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

