2012-05-04 47 views
0

我的東西工作了整整一天一夜,但好像我沒有得到任何進一步的使用它,因爲它是一個有點複雜,我真正學到:(越來越陣列和更換的空間與逗號

該代碼是這樣的:

$aDoor = $_POST['zeilenid']; 
    if(empty($aDoor)) 
    { 
    echo("You didn't select anything."); 
    } 
    else 
    { 
    $N = count($aDoor); 
    echo("You selected $N entry ID(s): "); 
    for($i=0; $i < $N; $i++) 

    { 
     $str = $aDoor[$i]; 
     $str = ereg_replace(" ",",",$str); 
     echo($str . " "); 
    } 
    } 

它不工作壽 - 我想要的ID,這將顯示爲不顯示他們是這樣的:8 9 10 而是這樣的:8,9,10 並保存在一個變量!我怎麼做到這一點?我在這裏做錯了什麼?

回答

0

只是嘗試:

$aDoor = $_POST['zeilenid']; 
    if(empty($aDoor)) 
    { 
    echo("You didn't select anything."); 
    } 
    else 
    { 
    $N = count($aDoor); 
    echo("You selected $N entry ID(s): "); 
    echo join(", ", $aDoor); 
    } 

加入結合了數組的所有元素爲一個串和插入的每個元件之間的所述第一參數

編輯:保存:

$str = join(", ", $aDoor); 
+0

該死的,好像像CHARM一樣工作!謝謝你的優秀和快速的幫助,哇! –

0
$clean_search = str_replace(' ', ',', $user_search); 

    $search_words = explode(' ', $clean_search); 

    $final_search_words = array(); 

    if (count($search_words) > 0) { 
     $final_search_words[] = $user_search; 
     foreach ($search_words as $word) { 

     if (!empty($word)) { 

      $final_search_words[] = $word; 

     } 

     } 

    } 

這代碼將用逗號替換空白空間,if條件用於僅用一個空格替換多餘的空格。