I use the following code to add a comma , at the end of every filename. After this using explode i put the rows on an array.
The images array if I echo it, it shows a.jpg,b.jpg,c.jpg, (please mind the last comma at the end of c.jpg)
How can I avoid adding a comma to the last found row?
<?php
while($image = mysql_fetch_array($images)) {
$images_path .= $image['FILE_NAME'].',';
}
$images_array = explode(",", $images_path);
?>
Make use of rtrim() by providing a comma as the second paramter as character mask
$images_path = rtrim($images_path,","); //<---- The added code
$images_array = explode(",", $images_path);
Why add it to a string and then convert it to an array, if you can add it straight away?
$images_array = array();
while($image = mysql_fetch_array($images)) {
$images_array[] = $image['FILE_NAME'];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With