Question: I been trying to find a better way of writing:

This works but there must be a cleaner way right?

```
public static function checkCourierCountry($courier, $country)
{
    if (isset(self::shippingGroups()['shippingGroups']['europe']) &&
        in_array($country, self::shippingGroups()['shippingGroups']['europe'])) {
        return true;
    }
    if (isset(self::shippingGroups()['shippingGroups']['fedex']) &&
        in_array($country, self::shippingGroups()['shippingGroups']['fedex'])) {
        return true;
    }
    if (isset(self::shippingGroups()['shippingGroups']['parcelForce']) &&
        in_array($country, self::shippingGroups()['shippingGroups']['parcelForce'])) {
        return true;
    }
    return false;
}

```

Answer: 
If `self::shippingGroups()` has any significant computational cost to run (like a database hit), you don't want to be calling it potentially three times. Call it once and store it in a variable. And any time you have repeated hunks of code that look the same, you can probably replace it with a loop:

```
$groups = self::shippingGroups()['shippingGroups'];
foreach (['europe', 'fedex', 'parcelForce'] as $group) {
    if (array_key_exists($group, $groups) && in_array($country, $groups[$group])) {
        return true;
    }
}   
return false;

```
```
public static function checkCourierCountry($courier, $country)
{
    $available = ['europe', 'fedex', 'parcelForce' ];
    foreach($available as $location)
        if (isset(self::shippingGroups()['shippingGroups'][$location]) &&
            in_array($country, self::shippingGroups()['shippingGroups'][$location]))
                return true;

    return false;
}

```