I searched everywhere but cannot find a solution that works for me.
I have the following:
$bedroom_array = array($studio, $one_bed, $two_bed, $three_bed, $four_bed);
In this example we can say:
$studio = '1';
$one_bed = '3';
$two_bed = '3';
Then I use the implode function to put a comma between all the values:
$bedroom_list = implode(", ", array_filter($bedroom_array));
echo $bedroom_list;
Then issued:
1, 2, 3
What I want to do is find the last comma in the line and replace it with &, so it will read:
1, 2 and 3
The string will not always be so long; it can be shorter or longer, for example. 1, 2, 3, 4, etc. I studied using substr but not sure if this will work for what I need?
source
share