2012-08-09 58 views
1

我想知道implode()加入元素值的順序是什麼。我希望它是在關鍵價值的基礎上做到的,但似乎並沒有這樣做。有沒有其他的功能可以讓你做到這一點?implode()加入元素值的順序

所以,如果我有:

$test_arr = array(2 => 'there', 1 => 'Hi ', 3 => '!'); 

,做

$stringy = implode($test_arr); 

變量$弦將包含字符串: '你好'?

當我用implode嘗試它時,我得到了'thereHi!',所以我猜數組有些如何跟蹤我定義元素的順序,然後內爆使用這些信息加入?

回答

6

implode()只是將它們在數組中定義的項加入。

做你想做的事,你需要理清什麼,如果第一:

$test_arr = array(2 => 'there', 1 => 'Hi ', 3 => '!'); 
ksort($test_arr, SORT_NUMERIC); 

$stringy = implode($test_arr);