如何在 php 中删除字符串数组中的字符 ('') 并将结果显示为单个字符串?

phpserver side programmingprogramming

假设我们的字符串数组减去以下内容

$full_name= '["John Doe","David Miller","Adam Smith"]';

我们希望输出为单个字符串 −

John Doe, David Miller, Adam Smith

为此,请使用 json_decode()。

示例

PHP 代码如下

<!DOCTYPE html>
<html>
<body>
<?php
$full_name= '["John Doe","David Miller","Adam Smith"]';
$full_name = json_decode($full_name);
$filterData = array_filter(array_map('trim', $full_name));
$output = implode(', ', $filterData);
echo "The Result in one string=",$output;
?>
</body>
</html>

输出

这将产生以下输出 −

The Result in one string=John Doe, David Miller, Adam Smith

相关文章