Stop the commas!!! ( or knowing when you're at the end of an array )



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

.



Relevant Pages

  • Re: [C++] using arrays in a class
    ... you cannot use your Cities class in a GUI program. ... You do not allocate storage for your array. ... This has undefined behavior since you haven't initialized 'city'. ... Do not use literal constants. ...
    (comp.programming)
  • Re: Simple Loop
    ... Cities in 3 columns: ... So I need to rearrange the array of strings so that my Display Loop ... Note that the expressions for row and col could be substituted ...
    (sci.math)
  • Re: Newbie : How to store 50 data elements effciently
    ... Michigan -> Dearborn etc... ... Now, all that said, it seems to me that a multi-dimensional array isn't really what you want here. ... you are not limited to three cities for each state...you can put as many into each array as you like). ... For example, instead of a string[], you could use a List, which would allow you to add or remove states dynamically much more simply than would be possible with a string. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simple Loop
    ... I have an array of strings. ... The loop that displays the cities do it the following way: ... Madrid New York Paris ...
    (sci.math)
  • Re: Calculating distances in O(1)
    ... >> Find the total distance between any two cities if: ... >> source city destination city distance ... Create an array of distances from city 0. ...
    (comp.programming)