-1
`<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>

<body>

<?php 

for( $x=1 ; $x<=10 ; $x++){
echo "$x".",";
}
?>
</body>
</html>`

1.output =1,2,3,4,5,6,7,8,9,10,

  1. i have this output. how can i remove the last comma? your help is needed.
miken32
  • 42,008
  • 16
  • 111
  • 154
  • 1
    I see over 3000 posts on this site when I search for [remove last comma](https://stackoverflow.com/search?q=remove+last+comma). This is a fairly common programming issue which should be easy to track down with some searching. – Josh Dec 05 '17 at 04:01

2 Answers2

2
<?php 
for( $x=1 ; $x<=10 ; $x++){
echo "$x";
if($x!=10)
echo ",";
}
?>

Check for the last iteration and avoid ','

Sooraj N Raju
  • 622
  • 7
  • 16
2

You can remove the last comma using join.

echo join(',', range(1,10));
drumhellerb
  • 381
  • 1
  • 7