View Single Post
  #2  
Old 08-19-2006, 09:41 AM
azhar azhar is offline
OSP Starters
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
azhar is on a distinguished road
Default

I think the simpliest way would be to check for the size, use ifs/case to check if its one, two or three or more. then for 3 or more. loop through the array and print it with commas until you get to the item in the array with an index that is two less then the size. then use an and.

something like:


PHP Code:
if(sizeof($artists) >=3){
for($i ==0; $i < sizeof($artists); $i++){
if($i < sizeof($artists) - 2){
echo $artists[$i] . ", ";
}
else if($i == sizeof($artists) - 2){
echo $artists[$i] . " and ";
}
else{
echo $artists[$i];
}
}

i didn't test this so there is probably some missing semi colans and such but it should give you the general idea. -- 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
  #2  
Old 08-19-2006, 09:41 AM
azhar azhar is offline
OSP Starters
 
Join Date: Mar 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
azhar is on a distinguished road
Default

I think the simpliest way would be to check for the size, use ifs/case to check if its one, two or three or more. then for 3 or more. loop through the array and print it with commas until you get to the item in the array with an index that is two less then the size. then use an and.

something like:


PHP Code:
if(sizeof($artists) >=3){
for($i ==0; $i < sizeof($artists); $i++){
if($i < sizeof($artists) - 2){
echo $artists[$i] . ", ";
}
else if($i == sizeof($artists) - 2){
echo $artists[$i] . " and ";
}
else{
echo $artists[$i];
}
}

i didn't test this so there is probably some missing semi colans and such but it should give you the general idea. -- 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