How to remove a character (‘’) in string array and display result in one string php?


Let’s say the following is our string array −

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

We want the output in a single string −

John Doe, David Miller, Adam Smith

For this, use json_decode().

Example

The PHP code is as follows

 Live Demo

<!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>

Output

This will produce the following output

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

Updated on: 13-Oct-2020

258 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements