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
You need to use concatenation...
$string .= $value.',';
(notice the .
)...
Consider using implode for this specific scenario.
$string = implode(',', $employeeAges);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With