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

In PHP, you can remove characters from a string array and display the result as a single string using json_decode() to parse the JSON string, then implode() to join the array elements.

Let's say we have the following JSON string array −

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

We want to convert this into a single comma-separated string −

John Doe, David Miller, Adam Smith

Example

Here's how to parse the JSON string and convert it to a single formatted string −

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

// Decode JSON string to PHP array
$full_name = json_decode($full_name);

// Filter and trim array elements (removes empty values)
$filterData = array_filter(array_map('trim', $full_name));

// Join array elements with comma and space
$output = implode(', ', $filterData);

echo "The Result in one string = " . $output;
?>
The Result in one string = John Doe, David Miller, Adam Smith

How It Works

The process involves three main steps −

  • json_decode() − Converts the JSON string into a PHP array
  • array_filter() + array_map() − Trims whitespace and removes empty elements
  • implode() − Joins array elements with a specified delimiter (comma and space)

Conclusion

Use json_decode() to parse JSON strings into arrays, then implode() to combine array elements into a single string with your desired separator.

Updated on: 2026-03-15T09:36:51+05:30

352 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements