John Doe, David Miller, Adam Smith">
 Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

PHP ลบอักขระ (') ใน string array และแสดงผลในสตริงเดียว

สมมติ string array ของเราคือ -

$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