gpt4 book ai didi

php - 向数组添加默认值

转载 作者:行者123 更新时间:2023-11-29 02:54:01 25 4
gpt4 key购买 nike

我的 opencart product.php 控制文件中有以下代码。

$product_option_value_data = array();

foreach ($product_option['product_option_value'] as $product_option_value) {
$product_option_value_data[] = array(
'product_option_value_id' => $product_option_value['product_option_value_id'],
'option_value_id' => $product_option_value['option_value_id'],
'quantity' => isset ($product_option_value['quantity']) ? $product_option_value['quantity'] : '1',
'subtract' => $product_option_value['subtract'],
'price' => isset ($product_option_value['price'])? $product_option_value['price'] : '27.99',
'price_prefix' => $product_option_value['price_prefix'],
'points' => $product_option_value['points'],
'points_prefix' => $product_option_value['points_prefix'],
'weight' => $product_option_value['weight'],
'weight_prefix' => $product_option_value['weight_prefix']
);
}

我需要为数量、价格、减去添加默认值。任何帮助将不胜感激。

最佳答案

你快到了。你已经为你的两个元素做到了。只需为 subtract 添加相同的检查。

$product_option_value_data = array();
foreach ($product_option['product_option_value'] as $product_option_value) {
$product_option_value_data[] = array(
'product_option_value_id' => $product_option_value['product_option_value_id'],
'option_value_id' => $product_option_value['option_value_id'],
'quantity' =>
isset ($product_option_value['quantity']) ?
$product_option_value['quantity'] :
'1', // THE DEFAULT FOR QUANTITY
'subtract' =>
isset ($product_option_value['subtract']) ?
$product_option_value['subtract'] :
'22', // THE DEFAULT FOR SUBTRACK
'price' =>
isset ($product_option_value['price']) ?
$product_option_value['price'] :
'27.99', //THE DEFAULT FOR PRICE
'price_prefix' => $product_option_value['price_prefix'],
'points' => $product_option_value['points'],
'points_prefix' => $product_option_value['points_prefix'],
'weight' => $product_option_value['weight'],
'weight_prefix' => $product_option_value['weight_prefix']
);
}

希望对你有帮助

关于php - 向数组添加默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32690454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com