1. 程式人生 > >extract_by_one 根據二維陣列中某欄位來提取陣列資訊,檢視有無重複資訊

extract_by_one 根據二維陣列中某欄位來提取陣列資訊,檢視有無重複資訊

    public function tt(){

        $param =  array(
            array (
                'hykno'         => '2222222-CB',
                'tcdk_fid'      => '458B6D70-FB7F-47AE-8356-777777777777',
                'totalamount'   => '0',
                'offsetamount'  => '90.0',
                
'postamount' => '0', 'hysyamout' => '10.0', 'protypeid' => '1', ), array ( 'hykno' => '2222222-CB', 'tcdk_fid' => '458B6D70-FB7F-47AE-8356-777777777777',
'totalamount' => '0', // 需要支付的錢 'offsetamount' => '5.0', // 抵扣分類1下5.0份; 'postamount' => '0', // 運費 'hysyamout' => '5.0', 'protypeid' => '1', ), array (
'hykno' => '2222222-CC', 'tcdk_fid' => '458B6D70-FB7F-47AE-8356-777777777777', 'totalamount' => '0', // 需要支付的錢 'offsetamount' => '5.0', // 抵扣分類1下5.0份; 'postamount' => '0', // 運費 'hysyamout' => '5.0', 'protypeid' => '7', ), array ( 'hykno' => '2222222-CC', 'tcdk_fid' => '458B6D70-FB7F-47AE-8356-777777777777', 'totalamount' => '0', // 需要支付的錢 'offsetamount' => '5.0', // 抵扣分類1下5.0份; 'postamount' => '0', // 運費 'hysyamout' => '5.0', 'protypeid' => '7', ), array ( 'hykno' => '2222222-DD', 'tcdk_fid' => '458B6D70-FB7F-47AE-8356-777777777777', 'totalamount' => '0', // 需要支付的錢 'offsetamount' => '5.0', // 抵扣分類1下5.0份; 'postamount' => '0', // 運費 'hysyamout' => '5.0', 'protypeid' => '3', ) ); //$this->merger_by_one($param,'protypeid',['totalamount','offsetamount','postamount','hysyamout']); $this->extract_by_one($param,'hykno'); } /*** * @param $param * @param $one_str '根據二維陣列中某欄位來提取陣列資訊,檢視有無重複資訊' */ public function extract_by_one($param,$one_str){ $u = array(); foreach ($param as $k => $v){ if (!in_array($v[$one_str],$u)){ $u[] = $v[$one_str]; } } $data = array(); foreach ($u as $uk => $uv) { foreach ($param as $pk => $pv) { if ($pv[$one_str] == $uv){ $data[$uv][] = $pv; } } } //$data = array_values($data); dump($data); }

[2222222-CB] => Array
(
[0] => Array
(
  [hykno] => 2222222-CB
  [tcdk_fid] => 458B6D70-FB7F-47AE-8356-777777777777
  [totalamount] => 0
  [offsetamount] => 90.0
  [postamount] => 0
  [hysyamout] => 10.0
  [protypeid] => 1
)

 
 

[1] => Array
(
  [hykno] => 2222222-CB
  [tcdk_fid] => 458B6D70-FB7F-47AE-8356-777777777777
  [totalamount] => 0
  [offsetamount] => 5.0
  [postamount] => 0
  [hysyamout] => 5.0
  [protypeid] => 1
)

 
 

)

 
 

[2222222-CC] => Array
(
[0] => Array
(
  [hykno] => 2222222-CC
  [tcdk_fid] => 458B6D70-FB7F-47AE-8356-777777777777
  [totalamount] => 0
  [offsetamount] => 5.0
  [postamount] => 0
  [hysyamout] => 5.0
  [protypeid] => 7
)

 
 

[1] => Array
(
  [hykno] => 2222222-CC
  [tcdk_fid] => 458B6D70-FB7F-47AE-8356-777777777777
  [totalamount] => 0
  [offsetamount] => 5.0
  [postamount] => 0
  [hysyamout] => 5.0
  [protypeid] => 7
)

 
 

)

 
 

[2222222-DD] => Array
(
[0] => Array
(
  [hykno] => 2222222-DD
  [tcdk_fid] => 458B6D70-FB7F-47AE-8356-777777777777
  [totalamount] => 0
  [offsetamount] => 5.0
  [postamount] => 0
  [hysyamout] => 5.0
  [protypeid] => 3
)

 
 

)