得到一個獨特的逗號分隔字符串我有一個PHP字符串如何從一個非唯一的字符串在PHP
$select_columms = 'pid, p.title, caption, filepath, filename, encaption, user1, user2, user3, user4, user5, user6, ult_puja, p.title, user2, user3';
,所以我有這個想法我能得到一個唯一的字符串,這行代碼
$select_columns = implode(',', array_unique(array_filter(explode(',',$select_columns))));
,但它似乎並沒有工作,你可以看到我缺少什麼?
編輯: 感謝的幫助下,我最終的代碼是:
$select_columns = implode(',', array_filter(array_unique(explode(',', $select_columns))));
其輸出$select_columns = 'pid, p.title, caption, filepath, filename, encaption, user1, user2, user3, user4, user5, user6, ult_puja'
我使用array_filter的情況下,我有一個像', pid,'
所以,你的意思是你想刪除出現在您的逗號分隔字符串重複值,並留下輸出爲逗號分隔字符串? – Neddy 2011-02-25 05:31:26
正是@Neddy邏輯創建select語句是導致重複字段進行查詢 – 2011-02-25 05:40:53
誰能告訴我,爲什麼各功能的順序所作的區別?作爲@amitchd的 – 2011-02-25 05:47:53