Sorry if this is confusing. It’s tough for me to put into words having beginner knowledge of PHP.
I’m using the following foreach loop:
foreach ($_POST['technologies'] as $technologies){
echo ", " . $technologies;
}
Which produces:
, First, Second, Third
What I want:
First, Second, Third
All I need is for the loop to skip the echo ", " for the first key. How can I accomplish that?
You can pull out the indices of each array item using
=>and not print a comma for the first item:Or, even easier, you can use implode($glue, $pieces), which “returns a string containing a string representation of all the array elements in the same order, with the glue string between each element”: