Question: I am stuck with a problem, I have fetched some values from a MySQL query and put them in to an array like so:

```
$add1 = $location->address1;
$add2 = $location->address2;
$twn = $location->town;
$pcode = $location->postcode;
$latitude = $location->lat;
$longitude = $location->lng;

$fullAddress = [$add1, $add2, $twn, $pcode];

$string = rtrim(implode(',', $fullAddress), ',');

echo $string;

```

so that I can echo out a users address. The problem I am getting is that even if one of these values does not exist (and some don't because they are not all required fields), the comma is still echoed to the screen like:

```
add1,, town, br2 5lp 

```

because there is an empty value in the database.

What I want to achieve is something like:

```
add1, town, br2 5lp 

```

if the second part of the address is missing.

Can anyone help me figure this out?

Answer: 
try this.

```
$fullAddress = [$add1, $add2, $twn, $pcode];
$string = implode(',', array_filter($fullAddress, 'strlen'));
echo $string;

```
What you need is to assure array `$fullAddress` have no empty value, so php built-in function [array\_filter](http://php.net/manual/en/function.array-filter.php) make this purpose very easy. 

Just change your last codes to:

```
$string = implode(',', array_filter($fullAddress));
echo $string;

```

If the second parameter of `array_filter` is not supplied, all entries of array equal to FALSE will be removed. So just simply use `array_filter($fullAddress)` it make the code more clear and simple.