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'
);
精彩评论