Giddy Rob Posted February 9, 2007 Share Posted February 9, 2007 Hi, I have an array that i need to put the values into a variable and seperate by |. I have tried this but it misses the first value out and puts a | at the end, which i don't want. $count=0; while($count < sizeof($alsolike)){ $mightlike=$mightlike."|".next($alsolike); $count++; } If i have four values in the array from 1-4 I would like to put it in a variable so it looks like this "1|2|3|4" Can anyone help me? Rob Link to comment https://forums.phpfreaks.com/topic/37795-putting-an-array-in-a-variable-sep-by/ Share on other sites More sharing options...
Orio Posted February 9, 2007 Share Posted February 9, 2007 You can use implode(): echo implode("|", $alsolike); Orio. Link to comment https://forums.phpfreaks.com/topic/37795-putting-an-array-in-a-variable-sep-by/#findComment-180799 Share on other sites More sharing options...
offsprg01 Posted February 9, 2007 Share Posted February 9, 2007 "If i have four values in the array from 1-4 I would like to put it in a variable so it looks like this "1|2|3|4"" you'll have to sort your array before you put it in to your variable. to get rid of your extranous "|" you need to check the total length of the arry and if end of array, then skip the "|". not sure exactly how you'd do that as i'm just picking up on array in php myself. if i can figure it out i'll post it here, as i am working on something similar myself. Link to comment https://forums.phpfreaks.com/topic/37795-putting-an-array-in-a-variable-sep-by/#findComment-180802 Share on other sites More sharing options...
Giddy Rob Posted February 9, 2007 Author Share Posted February 9, 2007 Quality, didn't know there was an implode(). Good man Cheers Rob Link to comment https://forums.phpfreaks.com/topic/37795-putting-an-array-in-a-variable-sep-by/#findComment-180815 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.