I got stuck with the nuance:
//1 - get mysql results into array
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
array_push($my_array, $row['fruit_name']);
}
//2 - sort array
sort($my_array);
//3 - convert array to json
json_encode($my_array);
OUTPUT:
['banana\r', 'apple\r', 'orange\r']
I have tried to remove \r with str_replace("\r", "", $my_array), but to no avail.
It seems str_replace does not work for any replace at all
Thanks!