Question: I have this simple for loop to echo an array:

```
for ($i = 0; $i < count($director); $i++) {
   echo '<a href="person.php?id='.$director[$i]["id"].'">'.$director[$i]["name"].'</a>';
}

```

The problem here is that when more than one element is in the array then I get everything echoed without any space between. I want to separate each element with a comma except the last one.

I can't use `implode` so I'm looking for another solution

Answer: 
This should work. It's better I think to call `count()` once rather than on every loop iteration.

```
$count = count($director);
for ($i = 0; $i < $count; $i++) {
   echo '<a href="person.php?id='.$director[$i]["id"].'">'.$director[$i]["name"].'</a>';

   if ($i < ($count - 1)) {
      echo ', ';
   }
}

```
How about something like this? You may want to store the result of "count($director)" in a variable outside the loop so that you do not have to waste resources recalculating it each time the loop is run.

```
for($i=0; $i<count($director);$i++){
   echo '<a href="person.php?id='.$director[$i]["id"].'">'.$director[$i]["name"].'</a>';
   if($i!=count($director)-1){echo ',';}
}

```