Stop the commas!!! ( or knowing when you're at the end of an array )
- From: "phpCodeHead" <phpcodehead@xxxxxxxxx>
- Date: 28 Dec 2006 11:17:20 -0800
Hi all,
I am looking for a good way to know when I am at the end of a
comma-separated list of array values.
My code is simple (as well as I'm sure is the solution I'm looking for;
and YES I've search the php manual!! Arrggghh! )
Anyway the code goes like this:
...
<td><select name="pref_cities[]" multiple size="6">
<option>Nagpur</option>
<option>Mumbai</option>
<option>Bangalore</option>
<option>Chennai</option>
<option>Kolkatta</option>
</select></td>
...
<?php
$cities = $_POST['pref_cities'];
foreach ($cities as $city) {
echo $city . ", ";
}
?>
I want to know when I'm at the last element in $cities[] so that I can
output a period (.) instead of a comma (,).
Thanx all! Have a HAPPY NEW YEAR!!
Gene
.
- Follow-Ups:
- Re: Stop the commas!!! ( or knowing when you're at the end of an array )
- From: Geoff Berrow
- Re: Stop the commas!!! ( or knowing when you're at the end of an array )
- From: Ian Taylor
- Re: Stop the commas!!! ( or knowing when you're at the end of an array )
- Prev by Date: posting with cURL problem
- Next by Date: Re: Stop the commas!!! ( or knowing when you're at the end of an array )
- Previous by thread: posting with cURL problem
- Next by thread: Re: Stop the commas!!! ( or knowing when you're at the end of an array )
- Index(es):
Relevant Pages
|