Remove comma from last word

hello

i have string like as
‘baba’,‘ramu’,‘sunder’,‘ajay’,

i want remove last comma as in this format
‘baba’,‘ramu’,‘sunder’,‘ajay’

Hi,

You want the [fphp]rtrim[/fphp] function for that:


$originalString = "'baba','ramu','sunder','ajay',";
$trimmedString = rtrim($originalString, ',');

echo $trimmedString;
// Outputs: 'baba','ramu','sunder','ajay'

thanks sir
i am trying to this code

$query = "SELECT * FROM fetchvalueinarray"; 	
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
    $allname=$row['name'];
	$b="'$allname'".',';
	echo $b;

but comma not remove

So, try changing your code like this:


$allnames = '';

$query = "SELECT * FROM fetchvalueinarray"; 	
$result = mysql_query($query) or die (mysql_error());

while($row = mysql_fetch_array($result)) {
    $allnames .= "'$row[name]',";
}

$allnames = rtrim($allnames, ',');
echo $allnames;

Also, please be aware that the mysql_* functions have been deprecated and will eventually be removed from PHP. It’s better to switch to mysqli or PDO (read more here: http://www.sitepoint.com/forums/showthread.php?1182768-STOP-using-mysql-migrating-to-procedural-mysqli).

thanku sir

one another think if i want
result in double as a " " so what i do please suggest me
“baba”,“ramu”,“sunder”,“aja”

Sure, just change this line:

$allnames .= "'$row[name]',";

to

$allnames .= "\\"$row[name]\\",";

thanku sir
my problem is solved