It might be a simple task. But I am new to PHP.
I am creating a string of values getting from database for a specific purpose.
How to remove last char from s
You might be better of just to use implode instead of this loop?
implode ( "##" , $dataarray );
<?php $str = "1,2,3,4,5,"; echo chop($str,","); ?>
It will remove last comma (,) from the string $str
Use substr:
$str = substr($str,0, -2);
http://php.net/manual/en/function.substr.php