Foreach: put each of the loop result in one variable

Hi,

I think this is probably a very simple but I can get my head around! How can I put each of the loop result in one variable only? for instance,

$employeeAges;
$employeeAges["Lisa"] = "28";
$employeeAges["Jack"] = "16";
$employeeAges["Ryan"] = "35";
$employeeAges["Rachel"] = "46";
$employeeAges["Grace"] = "34";

foreach( $employeeAges as $key => $value){
	$string = $value.',';
}

echo $string; 
// result 34,
// but I want to get - 28,16,35,46,34, - as the result

Many thanks,
Lau

oh this is a great trick! thanks :smiley:

To avoid having to run the foreach loop, you could also just do:

$string = implode(',', array_values($employeeAges));

append it with a dot


$string .= $value.',';

thanks so much! :slight_smile: