这个循环遍历list,并删除其中元素的错误已经犯了两次了!!
谨记谨记,切勿再犯错!!
public function filterUnabsorbPup($arrInput, $arrResult){ //20200716 Apollo实验:如果推荐上车点为非吸附,则不返回推荐上车点 $strApolloName = "global_filter_unabsorb_pup"; $arrApolloParam = array( "pid" => $arrInput['passenger_id'], "location_country" => $arrInput['canonical_country_code'], "key" => $arrInput["passenger_id"], ); $arrNeedGetParam = array( "filter_pup" => "1", ); $arrApolloFilterRes = $this->util->apolloABtest($strApolloName, $arrApolloParam, $arrNeedGetParam); if($arrApolloFilterRes["allow"] == true) { $arrApolloParam = $arrApolloFilterRes["apollo_param"]; //需要过滤非吸附的上车点 if (!empty($arrApolloParam) && intval($arrApolloParam['filter_pup']) == 1) { for ($i=0; $i< count($arrResult["rec_start_points"]); $i++) { if ($arrResult["rec_start_points"][$i]["base_info"]["is_recommend_absorb"] == 0) { array_splice($arrResult["rec_start_points"],$i,1); //这里会有问题!!! } } } } return $arrResult; }
在循环中用 array_splice 函数去掉其中的元素,会改变原来list的大小,再次循环遍历,一定会有问题!!!
不要再犯这种低级错误啦!!!