Implode and remove empty values
- by binoy
Hi,
I have an array like this
$arr = array('name' => 'John',
'address' => 'IInd Street',
'state' => '',
'country' => 'US');
I want to display the values as
John,
IInd Street,
US
(ie, If any value is empty, I don't want to display comma and break over there)
I could able to display this with the following code
$values = implode(',', $arr);
echo $str = implode(',<br />',array_filter(explode(',', $values)));
Is there any better way to do this ?