连接PHP数组中的元素

时间:2010-09-11 18:47:44

标签: php arrays

如何在下面打开以下数组,使其看起来像使用PHP的示例2.

示例1数组。

Array ( [0] => &sub1=a1 [1] => &sub2=aa [2] => &sub3=glass-and-mosaics [3] => &sub4=guides-and-reviews [4] => &sub5=silent-movies [5] => &sub6=even-more-eastern-religions-and-philosophies ) 

示例2。

&sub1=a1&sub2=aa&sub3=glass-and-mosaics&sub4=guides-and-reviews&sub5=silent-movies&sub6=even-more-eastern-religions-and-philosophies

4 个答案:

答案 0 :(得分:3)

可以使用implode

答案 1 :(得分:3)

您可以使用implode功能。

$arr = array(0 => '&sub1=a1',1 => '&sub2=aa');
$str = implode('',$arr);

答案 2 :(得分:1)

只需执行$myVar = implode('', $array);

答案 3 :(得分:1)

如果这是网址的查询片段,请改为使用http_build_query

echo http_build_query(
   'sub1'=>'a1',
   'sub2'=>'aa',
   'sub3'=>'glass-and-mosaics',
   'sub4'=>'guides-and-reviews',
   'sub5'=>'silent-movies',
   'sub6'=>'even-more-eastern-religions-and-philosophies'
);