Say I have an array:
$array = Array(
'foo' => 5,
'bar' => 12,
'baz' => 8
);
And I'd like to print a line of text in my view like this:
"The values are: foo (5), bar (12), baz (8)"
What I could do is this:
$list = Array();
foreach ($array as $key => $value) {
$list[] = "$key ($value)";
}
echo 'The values are: '.implode(', ',$list);
But I feel like there should be an easier way, without having to create the $list array as an extra step. I've been trying array_map and array_walk, but no success.
So my question is: what's the best and shortest way of doing this?