Jump to content

[SOLVED] Get array values into one variable as a string


alwoodman

Recommended Posts

I have an array ($hotels) which contains hotel ids. I want to be able to pass all the variables into one variable ($arrayvalues) in the following format hotel_ids=34505,34625,34655,34672,34753,34787,34903,35288,35329,35426

 

 

$hotels = array();
	$y=0;
	do {

		if($y==$totalRows_getHotels-1){

			array_push($hotels, ",".$row_getHotels['Hotel_Id']."&");

		}elseif ($y==0){

			array_push($hotels, "hotel_ids=".$row_getHotels['Hotel_Id']."");

		}else{

			array_push($hotels, ",".$row_getHotels['Hotel_Id']."");

		}

		$y++;
		// echo $y;

	} while ($row_getHotels = mysql_fetch_assoc($getHotels));

 

I've tried looping through like this to output the values:

 

		
			foreach($hotels as $value){
				echo $value;
			}

 

but it only outputs the last value. I want to be able to pass all the values through to a url like this

 

$url = "http://www.getmyhotels.com?hotel_ids=".$arrayvalues."&arrival_date=".$newcheckin."&departure_date=".$newcheckout."";

Link to comment
Share on other sites

what the guy above me said.

 

then when you want to pull the data back apart, use explode:

 

$hotels = explode(",", $hotel_ids);

 

it puts the data into $hotels as an array with numeric keys. $hotels[0] would have your first item, $hotels[1] would have the second, so on so forth.

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.