alwoodman Posted August 29, 2009 Share Posted August 29, 2009 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 https://forums.phpfreaks.com/topic/172380-solved-get-array-values-into-one-variable-as-a-string/ Share on other sites More sharing options...
Prismatic Posted August 29, 2009 Share Posted August 29, 2009 $hotel_ids = implode(",", $hotels); Link to comment https://forums.phpfreaks.com/topic/172380-solved-get-array-values-into-one-variable-as-a-string/#findComment-908879 Share on other sites More sharing options...
5kyy8lu3 Posted August 29, 2009 Share Posted August 29, 2009 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 https://forums.phpfreaks.com/topic/172380-solved-get-array-values-into-one-variable-as-a-string/#findComment-908882 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.