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

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.

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.