如何在字串陣列中刪除一個字元('')並在一個字串中顯示結果?


假設我們的字串陣列如下:

$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

更新時間:2020 年 10 月 13 日

285 次瀏覽

開啟你的 職業生涯

透過完成該課程,獲得認證

開始學習
廣告
© . All rights reserved.