D
D
dez64ru2016-08-07 01:32:25
PHP
dez64ru, 2016-08-07 01:32:25

How to loop through an array separated by commas?

How to loop through an array separated by commas, and put a dot after the last element?
There is an associative array $tags,

Array ( [0] => Адин [1] => Два[2] => Три [3] => Четыре[4] => Пять)

Code for iterating an array.
foreach ($tags as $tgs) {
  echo $tgs;
}

There was an idea with counting the number of elements in an array, but the code is too complicated. Are there vanilla tags for this case?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dez64ru, 2016-08-07
@dez64ru

Krch, did not understand anything from what was written. I threw a simple script here with crutches.

$cnt = count($string2);
$i = 0;
while ($i < $cnt-1)
{
    echo $string2[$i].", ";
    $i++;
}
echo (end($string2)).".";

J
jaxel, 2016-08-07
@jaxel

$str = implode(',', $array) . '.';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question