当我连接 PHP 变量以形成一个逗号分隔的列表时,它会添加一个逗号,无论该变量是否具有值。
将变量连接到逗号分隔列表时如何删除不必要的逗号?
try {
$stmt = $conn->prepare("SELECT * FROM customer_info WHERE user_id = :user_id");
$stmt->bindValue(':user_id', $user_id);
$stmt->execute();
}
catch (PDOException $e) {
echo $e->getMessage();
}
$search = array('_', ',', 'Null');
$replace = array(' ', ', ', '');
$rows = str_replace($search, $replace, $row);
$merged_likes = $rows['items_like'] . ", " . $rows['first_like'] . ", " . $rows['second_like'] . ", " . $rows['third_like'];
echo $merged_likes;