在表列中分配数组值

时间:2016-07-13 13:01:15

标签: php loops

我有三列有一定百分比的限制。我希望以这样的方式将一组值分配给三列首先检查客户1然后2然后3并从客户3,2,1开始再次从1,2,3等等。还要检查每个不超过列限制的值。剩余的数组值应该在分配了大百分比的列中分配。

Array : $stone_doll_inner_arr = array(1=>'67212','37256','32909','29847','28529','27643','25356','25274','23604','23058','18581');

我试过

for($m=1;$m<=1;$m++){


    for($n=1;$n<=count($stone_doll_inner_arr);$n++){    

        if ($n % 2 == 0) {
        $asc_desc = 'asc';
        }else{
        $asc_desc = 'desc';
        }


        //Query
        $sql_main_table = "select * from create_nemix_tbl where create_id = '".$getid."' order by percentage ".$asc_desc."";
        $qry_main_table = $con->query($sql_main_table);
        $num_main_table = $qry_main_table->num_rows;

        if ($n % 2 == 0) {
            $l = $num_main_table-1;

        }else{
            $l = 0;

        }


        while($row_main_table = $qry_main_table->fetch_array()){


                $stone_doll_val = $stone_doll_arr[$m];
                $stone_doll_val_perc = ($stone_doll_val * $row_main_table['percentage']) / 100;

                $pre_existing = isset($customer[$l]) ? array_sum($customer[$l]) : 0;
                $first_value = $pre_existing+$stone_doll_inner_arr[$n];

                $var = 0;
                if ($first_value <= $stone_doll_val_perc){

                        $customer[$l][] = $stone_doll_inner_arr[$n];
                        unset($stone_doll_inner_arr[$n]);
                        $var =1;
                }
                if($var == 1){
                    break;
                }   

        }



        if ($n % 2 == 0) {
            $l--;
        }else{
            $l++;
        }

    }

}


echo "<pre>";
print_r($customer);

表格我想要的脚本结构和输出 enter image description here

enter image description here

0 个答案:

没有答案
相关问题