开发者

Concatenate the elements in a PHP array

How can I turn the following array below so it looks like example 2 using PHP.

Example 1 array.

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 ) 

Example 2.

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


can use implode


You can use the implode function.

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


just do a $myVar = implode('', $array);


If this is a query fragment of a URL, use http_build_query instead:

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'
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜