Jump to content

Removing commas from a string and keeping it a string?


brian914

Recommended Posts

I have the following function, which takes a string with commas in it and attempts remove those commas. The way I have it here is that I use explode to take out the commas, which makes an array, and then iterate through that array to put a string back together without the commas.

 

function tags_to_sort_by( $sortMeta ) {

$sortByArray = explode(",", $sortMeta);

$sortByCount = count($sortByArray);

for ($i = 0; $i < $sortByCount; $i++) {

$sortByString += $sortByArray[$i];

}

return $sortByString;

}

 

What does not work is the following line:

$sortByString += $sortByArray[$i];

Somehow that outputs a 0, which I don't understand. It should output something like: arrayItem1 arrayItem2 array3 etc.

 

My question is if there either is an easier way to remove the commas from the original string or what I am doing wrong in this line:

$sortByString += $sortByArray[$i];  // I am trying to concatenate each part of the array back into the string.

 

Thanks a lot for help with this!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.