I have a $_SESSION array which I filter/sanitize by keys inside of a loop.
This produces a 2d array of qualifying data, but I want to reduce it to a flat associative array.
Theoretical input:
$_SESSION = [
// ...some unwanted row
'saved_query_something' => ['product_category' => 'for-women'],
'saved_query_something_else' => ['brand' => '7-diamonds'],
// ...some unwanted row
'saved_query_blah' => ['size' => 12],
'saved_query_blar' => ['color' => 882536],
];
This is my current code that doesn't correctly reduce the data structure while sanitizing.
foreach ($_SESSION as $k => $v) {
if (strstr($k, 'saved_query_') == true) {
$saved = array_merge($v);
}
}
The desired result:
[
'product_category' => 'for-women',
'brand' => '7-diamonds',
'size' => 12,
'color' => 882536,
]