2017-07-08 97 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) –

相关问题