Jump to content

merge array values as single variable


Orasion

Recommended Posts

Hi all,

 

I want to merge array values which I got from a loop

 

for($i=0; $i<count($_SESSION['code']); $i++){																
							for($j=0; $j<count($_SESSION['color'][$i]); $j++){									
								echo $_SESSION['code'][$i]."_".$_SESSION['color'][$i][$j]."_".$_SESSION['order'][$i][$j]."_".$_SESSION['totalcost'][$i][$j]."&";
								$order[] = $_SESSION['code'][$i]."_".$_SESSION['color'][$i][$j]."_".$_SESSION['order'][$i][$j]."_".$_SESSION['totalcost'][$i][$j]."&";			

							}
						}

 

as you can see, the loop will output an array $order[].

Now I want to list the $order[] values as a single variable say $total;

So if $order have 3 output like this :

 

$order[0] = "echo0&";
$order[1] = "echo1&";
$order[2] = "echo2&";

 

I want to merge them all into $mergeorder and I expect the value will be like this :

$mergeorder = "echo0&echo1&echo2&";

 

I know this is easy if $order is a fixed array but in this case $order have dinamic value from the loop.

Help me with this case, Ive been thinking this a whole week  :confused:

 

P.S : fyi, what I plan to do with $mergeorder is pass it to database.

 

Thank you in advance

Link to comment
https://forums.phpfreaks.com/topic/264169-merge-array-values-as-single-variable/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.