我正在构建一个购物车 php 文件,它将查询数据库中的产品(以及用户添加到购物车中的每种产品的数量)。但我无法理解如何处理“逗号分隔的字符串”。到目前为止,这是我的代码中的循环:
//Loop through your cart array (foreach productID's quantity in cart):
$_SESSION['numItems'] = $cart;//Update the number of items in your cart
//Build a comma-delimited string in $prodIDStr containing the product
//ID’s of the products currently in our cart array:
$prodIDStr = "";//STACKOVERFLOW QUESTION
if($_SESSION[numItems] = 0){//If cart it empty:
print "<h3>Your shopping cart is empty!</h3>\n";
}
Else{//if cart is not empty:
//remove trailing comma from $prodIDstr:
究竟什么是逗号分隔的字符串,删除尾随逗号有什么作用?