php语法


判断是否为空

if (!$cart_num || !$cart_info) return [];

 

数组循环

$compute_arr = ['coupon_price', 'integral_price', 'postage_price', 'use_integral', 'one_brokerage', 'two_brokerage', 'sum_true_price'];
foreach ($compute_arr as $field) {
    if (!isset($cart_info[$field]) || !$cart_info[$field] || $is_gift) {
        $new_cart_info[$field] = 0;
        continue;
    }
    $scale = 2;
    if ($field == 'use_integral') $scale = 0;

    if (!$i) {//拆出
        $new_cart_info[$field] = bcmul((string)$cart_num, bcdiv((string)$cart_info[$field], (string)$cart_info['cart_num'], 4), $scale);
    } else {
        $field_number = bcmul((string)bcsub((string)$cart_info['cart_num'], (string)$cart_num, 0), bcdiv((string)$cart_info[$field], (string)$cart_info['cart_num'], 4), $scale);
        $new_cart_info[$field] = bcsub((string)$cart_info[$field], (string)$field_number, $scale);
    }
}

 

数组长度

$data['uid'].count()

 

不等于

if($count !==$data['uid'].count()) {

}

 

字符串已逗号分隔为数组

explode(',', $data['uid'])

 

判断变量是否为数组

is_array($env)

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/281101.html

(0)
上一篇 2022年8月20日
下一篇 2022年8月20日

相关推荐

发表回复

登录后才能评论