2011-08-14 44 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