View Single Post
  #1  
Old 08-19-2006, 09:40 AM
instinctive instinctive is offline
Junior Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
instinctive is on a distinguished road
Question Variable, variables and variable

How can I echo an array of variables with commas + 'ands' where appropriate? For example, say there is an array of artist names such as:

bob, mary, john

how can I have php make use of commas and 'and' when displaying these? 'artists' array may only have one artist in which case I'd want it on it's own:

bob

if there are two variables then 'and' should be used:

bob and mary

but if there are three (or more) artists, commas and 'and' are needed:

bob, mary and john

Is there any way of doing this without having a switch of ifelse statement for each possible number of artists?
Thanks and bye -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  Webmaster Forums - View Single Post - Variable, variables and variable
View Single Post
  #1  
Old 08-19-2006, 09:40 AM
instinctive instinctive is offline
Junior Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
instinctive is on a distinguished road
Question Variable, variables and variable

How can I echo an array of variables with commas + 'ands' where appropriate? For example, say there is an array of artist names such as:

bob, mary, john

how can I have php make use of commas and 'and' when displaying these? 'artists' array may only have one artist in which case I'd want it on it's own:

bob

if there are two variables then 'and' should be used:

bob and mary

but if there are three (or more) artists, commas and 'and' are needed:

bob, mary and john

Is there any way of doing this without having a switch of ifelse statement for each possible number of artists?
Thanks and bye -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote