I have searched everywhere but can\'t find a solution that works for me.
I have the following:
$bedroom_array = array($studio, $one_bed, $two_bed, $t
strrpos finds the last occurrance of a specified string. $str = '1, 2, 3';
$index = strrpos( $str, ',' );
if( $index !== FALSE )
$str[ $index ] = '&';
Here's another way to do the replacement with a regular expression using a positive lookahead which doesn't require a backreference:
$bedroom_list = preg_replace('/,(?=[^,]*$)/',' &', implode(', ', $bedroom_array));