PHP: Display comma after each element except the last. Using 'for' statement and no 'implode/explode
Posted
by Jonathan
on Stack Overflow
See other posts from Stack Overflow
or by Jonathan
Published on 2010-05-19T15:09:06Z
Indexed on
2010/05/19
15:20 UTC
Read the original article
Hit count: 162
hi, so 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 cant use 'implode' so I'm looking for another solution... Anyone?
© Stack Overflow or respective owner