我有一个 for 循环,我希望能够将结果回显到字符串中。如何才能做到这一点?它只会将循环的最后一次运行回显到我的变量中,以便在循环外使用。
for ($i = 0; $i < $numItem; $i++) {
extract($cartContent[$i]);
$pricebands = array("1"=>"$pd_price1","2"=>"$pd_price2","3"=>"$pd_price3","4"=>"$pd_price4","5"=>"$pd_price5","6"=>"$pd_price6");
if(isset($loggedInfo['price'])){
$priceToShow = $pricebands[$loggedInfo['price']];
} else {
$priceToShow = $pricebands[1];
}
$productUrl = "index.php?c=$cat_id&p=$pd_id";
$subTotal += $priceToShow * $ct_qty;
$pd_name;
$ct_qty;
$productList = "L_NAME".$i."=".$pd_name."&L_AMT".$i."=".$priceToShow."&L_QTY".$i."=".$ct_qty."&";
}
$amount = $subTotal;
}
以及将 $productList 放入的变量
$nvpstr="&PAYMENTACTION=$paymentType&AMT=$amount&".trim($productList)."CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber&EXPDATE=".$padDateMonth.$expDateYear."&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName&STREET=$address1&CITY=$city&STATE=$state&ZIP=$zip&COUNTRYCODE=$countryCode&CURRENCYCODE=$currencyCode";