You can augment your existing filter function to also exclude features based on their geo information.
// this is the TX You don't want
$ignoreState="TX";
// filter features, remove those which are not of any of the desired event types
// and also remove those from $ignoreState
$alertFeatures = array_filter($features, function (array $feature) use ($alerts, $ignoreState) {
$eventType = $feature['properties']['event'];
$isValidEvent = in_array($eventType, $alerts);
$geocode = $feature['properties']['geocode']['UGC'][0];
$isValidState = substr($geocode, 0, 2) != $ignoreState;
return $isValidState && $isValidEvent;
});
The filter function is just a function that is supposed to return true
if you want the array item ($feature
) to be in the resulting array, or false
if you want the array item to be excluded from the resulting array.
In your case, you want the array item to the in the resulting array if its event is one of the whitelisted events ($alerts
) and if the state code ($state
) is not TX
.
6
solved PHP – Filter by value and omit in loop [duplicate]