This question already has an answer here:
I will do my best to explain this and keep it short as well. I am parsing a JSON file. I have created variables based on keys from the JSON and loop through it. I already have one array_filter that filters values in the loop I want to allow. What I am not sure of is how to go a step further and do another check and disallow by the value of a different key/variable.
In my JSON I have this key/object...
"geocode": {
"UGC": [
"TXZ179",
],
Now the varible I have created for this to get this value is like so...
$geocode = $currFeature['properties']['geocode']['UGC'][0];
Now if you notice the value it is
TXZ179
I only need to the first two letters from that value so I have stripped it down to show only the first two letters like so...
$state = substr($geocode, 0, -4);
This leaves me with the value of TX from above.
I explained that to explain this. I want to take that $state variable and filter out and omit values in my loop that = TX from that variable.
Before I loop through my parsed JSON I filter it by values that I want to SHOW like so...
//Lets filter the response to get only the values we want
$alerts = array(
'Tornado Warning',
'Severe Thunderstorm Warning',
'Hurricane Warning',
'Tropical Storm Warning',
'Flash Flood Warning',
'Flood Warning',
);
// filter features, remove those which are not of any of the desired event types
$alertFeatures = array_filter($features, function(array $feature) use ($alerts) {
$eventType = $feature['properties']['event'];
return in_array($eventType, $alerts);
});
// flip alerts, mapping names of alerts to index in array (we'll use it to order)
$order = array_flip($alerts);
// sort elements by order of event type as desired
usort($alertFeatures, function (array $a, array $b) use ($order) {
$eventTypeA = $a['properties']['event'];
$eventTypeB = $b['properties']['event'];
return $order[$eventTypeA] - $order[$eventTypeB];
});
This question has to do more with filter OUT by a certain value while already having an existing array_filter to ALLOW by certain values and how they can both co-exist.
So my problem is due to the lack of knowledge. I am not sure what function to use or how to disallow by the value of TX in the $state variable. From my knowledge array_filter is for to filter out values you want to keep. So how can I remove values with TX before I loop throw it and it passes the first array_filter.
</div>