2011-08-14 45 views
0

我有四組:$text[], $ytext[], $titles[], $ytitles[]破滅陣列和存儲爲完整的字符串

我想要做的就是破滅的陣列,文字和字幕,通過「」將它們存儲爲一個完整的字符串。但我想根據它們的位置(這是一個y座標整數)來排列它們。

例如:

$text[] = 
{1 => hello 
2=> again 
3 => more text 
} 

$ytext[] = 
{1 => 5 
2=> 10 
3 => 14 
} 

$titles[] = 
{1=> title 
2=> title2 
} 

$ytitles[] = 
{1=> 2 
2=> 11 
} 

所以這將是這樣的:title hello again title2 more text

+1

我不明白要求,你能舉出更多的例子嗎? – JRL

+0

最終結果基本上就是最後的句子.....根據由ytext和ytitles指定的每個單獨字符串的位置,文本和標題的單獨字符串將按照這樣的方式組織 – re1man

回答

1

擴大在安地列斯的解決方案,這是一個很好的想法,但也並非完全奏效,因爲沒有按array_merge()不保留數字鍵。您可以使用此解決方案:

$arr = array_combine($ytext, $text) + array_combine($ytitles, $titles); 
ksort($arr); 
echo implode(' ', $arr); 
0
$newText = array_combine($ytext, $text); // combine $ytext as keys and $text as values 
$newTitles = array_combine($ytitles, $titles); 
print implode(' ', array_merge($newText, $newTitles)); // merges and implode array