Jump to content

putting an array in a variable sep by |


Giddy Rob

Recommended Posts

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

"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.

 

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.