Jump to content

getting array items into one variable


alwoodman

Recommended Posts

Im trying to get the days tide information which is currently in the array $tides to echo out as part of a string $message

 


$tides = array();
do {

$newtideheight = round($row_TidesFeed['Height'] + 3, 0);	
$basedate = strtotime($row_TidesFeed['Time']);
$date1 = strtotime("-1 hour", $basedate);
$newdate = substr(date('H:i:s', $date1), 0, 5);

array_push($tides, rtrim($row_TidesFeed['State'], "W").''.$newdate);

} while ($row_TidesFeed = mysql_fetch_assoc($TidesFeed));

// This is what i need to echo ideally as one variable $alltides which will sit at the end of and be part of the $message.''.$alltides

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


$message = $message.' and the tides are $alltides';

 

thanks

 

Lee

Link to comment
https://forums.phpfreaks.com/topic/192954-getting-array-items-into-one-variable/
Share on other sites

You can take an array and implode it into a string i.e

<?php
$x = array('red','green','blue');
$string = implode(', ',$x);
print "My favourite colours are: ".$string;
?>

Hope this helps.

 

http://uk3.php.net/implode

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.