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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.