2017-07-08 140 views
-1

我正在嘗試array_combine將所有這些數組轉換爲具有唯一值的單個數組。在foreach循環中使用array_combine將多個數組轉換爲單個數組

$arr_ch_no = array(); 
     $arr_ch_no[] = "'***0***'"; 
     $sql = mysql_query("SELECT ship_name,voy_no from tb_veh_data_entry WHERE (ETAQ > '".date("Y-m-d")."' or (ETAQ <> '0000-00-00' and stock = 0 and stock_sale_date = '0000-00-00')) and (user_id = 'UI08-00000063' or user_id = 'UI09-00000111') and stock_country = 58 and ((buyer in ('6371','2509','2535') and arica = 0) or arica=4) group by ship_name,voy_no "); 
     while($row_no = mysql_fetch_array($sql)) 
     { 
      $str_no_ch = selFieldCon("tb_veh_data_entry","GROUP_CONCAT(frame_no)"," ship_name = '".$row_no['ship_name']."' and voy_no = '".$row_no['voy_no']."' and (user_id = 'UI08-00000063' or user_id = 'UI09-00000111') and stock_country = 58 and ((buyer in ('6371','2509','2535') and arica = 0) or arica=4) and ETAQ <> '0000-00-00' ".$this->condition.""); 
      $arr_no_ch = array(); 
      $arr_no_ch = explode(",",$str_no_ch); 
      if($str_no_ch != '') 
      foreach($arr_no_ch as $val) 
       $arr_ch_no[] = "'".$val."'"; 
     } 

這個查詢使用了foreach循環

$sql = "SELECT * FROM tb_veh_data_entry WHERE 1 ".$this->condition." "; 

我想這裏面的foreach。如何將其轉換爲foreach內的單個數組。

Array 
    (
     [0] => '***0***' 
     [1] => 'NCP100-0027131' 
    ) 
    Array 
    (
     [0] => '***0***' 
     [1] => 'NCP100-0027131' 
    ) 
    Array 
    (
     [0] => '***0***' 
     [1] => 'NCP100-0027131' 
    ) 

但我沒有得到任何東西。

+0

是你的實際代碼? – billynoah

+0

請定義您將多個數組轉換爲一個數組的步驟,預期的結果是什麼? – user10089632

+0

@billynoah更新。 –

回答

-1

這不是很好的解決方案。希望它能幫助你。

$data1 = array_column($array, 0, 1); 
$data2 = array_column($array, 1, 0); 

$data1Length = count($data1); 
$data2Length = count($data2); 

$result = []; 
if($data1Length > $data2Length) { 
    foreach($data1Length as $k => $v) { 
     $result[] = [$v, $k]; 
    } 
} else { 
    foreach($data1Length as $k => $v) { 
     $result[] = [$k, $v]; 
    } 
} 
+0

請首先看到:[回答](https://stackoverflow.com/help/answering)和[如何回答](https://stackoverflow.com/help/how-to-answer) –

相關問題