I have an array filled with these strings for example:
"1", "2", "3", "4", "5";
I have an foreach() loop, that loops through these items. It outputs all the items. Now, it outputs this:
1, 2, 3, 4, 5
But I want to output this:
1, 12, 123, 1234, 12345
How do I do this? Because the prev() function only applies to the one before the current item.
My code:
$array = array("1", "2", "3", "4", "5");
foreach ($array as $item){
echo $item;
}

array_slice()foreach($data as $key => $value) { echo implode(array_slice($data, 0, $key+1)), PHP_EOL; }orforeach(array_keys($data) as $key) { echo implode(array_slice($data, 0, $key+1)), PHP_EOL; }