标签:status 存在 color pre tsp bst uniq col function
// 定义瓶码字符串 $bianhaop_str = substr($bianhaop_str,1); $bianhaop_arr = explode(‘,‘, $bianhaop_str); if(!empty($bianhaop_arr)){ //判断本身是否存在重复项 if(count(array_unique($bianhaop_arr))!=count($bianhaop_arr)){ Db::rollback(); return [‘status‘=>0,‘msg‘=>‘导入的瓶码重复‘]; } //验证瓶码 $bplistarr=Db::name(‘goodlistsp‘)->where(‘bianhaop‘,‘neq‘,‘‘)->distinct(true)->field(‘bianhaop‘)->select(); if(!empty($bplistarr)){ $bplist=$this->array_to_arr($bplistarr, ‘bianhaop‘);//二维数组转一维 foreach ($bianhaop_arr as $bey => $bue) { if(in_array($bue, $bplist)){//在数组里是否存在某项 Db::rollback(); return [‘status‘=>0,‘msg‘=>‘瓶码‘.$bue.‘重复‘]; } } } }
//二维数组转一维数组
public function array_to_arr($array, $id)
{
$arr = array();
foreach ($array as $key => $val) {
array_push($arr, $val[$id]);
}
return $arr;
}
标签:status 存在 color pre tsp bst uniq col function
原文地址:https://www.cnblogs.com/zhangyouwu/p/14821494.html