2013-05-08 94 views
0

這是一個深夜,所以我知道這是一個非常簡單的問題。我有以下代碼:如何從範圍函數中獲得數組中的單個值

$letters = range('A', 'Z'); 
$inx = 0; 
$unique = false; 
$num = substr($vin,-6); 
while($unique != true){ 
    if($inx > 0){ 
     $num = substr($vin,-6) + $letters[$inx]; 
    } 
    $this->db->where('stockid', $num); 
    $query = $this->db->get('vehicles'); 
    if($query->num_rows() < 1){ 
     $unique = true; 
    } 
    $inx++; 
} 

我得到一個錯誤,因爲它不拉了一封信,將其添加到它規定的字符串:

$num = substr($vin,-6) + $letters[$inx]; 
+1

究竟是什麼錯誤?更重要的是,你究竟想要在這裏做什麼?這段代碼看起來像你可能會更好地在寫作之前獲得良好的夜間睡眠。 – deceze 2013-05-08 08:35:21

+5

因爲我假設你試圖連接字符串/字符,所以你最好使用'.'而不是'+'。 – 2013-05-08 08:36:58

+0

你需要一個很好的理由把查詢放在一個php循環中。你真的有嗎? – BlitZ 2013-05-08 08:37:12

回答

0

您可以嘗試使用它代替:

$num.=$letters[$inx]; 

$num = substr($vin,-6) + $letters[$inx]; 

因爲我們經常在Javascript中使用「+」。

相關問題