Orasion Posted June 14, 2012 Share Posted June 14, 2012 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 P.S : fyi, what I plan to do with $mergeorder is pass it to database. Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/264169-merge-array-values-as-single-variable/ Share on other sites More sharing options...
AMcHarg Posted June 14, 2012 Share Posted June 14, 2012 You might be interested in reading about the implode function. Quote Link to comment https://forums.phpfreaks.com/topic/264169-merge-array-values-as-single-variable/#findComment-1353770 Share on other sites More sharing options...
Orasion Posted June 14, 2012 Author Share Posted June 14, 2012 That is unbelievably easy solution after a whole week with no answer :'( :'( I guess it's showing how I am still inexperience (read : n00b) in PHP. Thank you so much, AMcHarg. Quote Link to comment https://forums.phpfreaks.com/topic/264169-merge-array-values-as-single-variable/#findComment-1353781 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.