In my web application, a user has the choice to enable and disable certain "notification preferences", their choices are added to an array for each possible category and alerts within a JSON object, this is then saved to the database, I'm trying to remove ALL mentions of a specific "channel" if it's set without having to know what to loop over and what nested items I have.
For instance, the following structure:
$channels = json_encode([
'domains' => [
'expiry' => ['mail', 'database', 'slack']
],
'ssl' => [
'expiry' => ['mail', 'database', 'slack']
],
'monitors' => [
'up' => ['mail', 'database', 'slack'],
'down' => ['mail', 'database', 'slack']
]
]);
$preferences = json_decode($channels);
I'd like to somehow find all mentions of **slack"" and then simply remove that item from my arrays, it may not always be in the same position, depending on what a user enables/disables...
I was thinking of using unset
or something similar?
How can I achieve this with my code?