tags:

views:

42

answers:

4

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
+3  A: 

can use implode

Crayon Violent
+3  A: 

You can use the implode function.

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

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

hacksteak25
+1  A: 

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