PHP: Implode an array and use each array value multiple times -
what want achieve following:
transform array:
['a','b','c'];
into string like:
"a a, b b, c c"
is there other way foreach-loop (like implode) achieve this?
if you're not looking loop through, use array_walk() function.
try this:
$input = ['a','b','c']; function test_alter(&$item, &$key) { $item = $item.' '.$item; } array_walk($input, 'test_alter'); echo implode(', ', $input);
output:
a a, b b, c c
Comments
Post a Comment