$utms = [
'utm_source' => $_POST['utm_source'] ?? null,
'utm_medium' => $_POST['utm_medium'] ?? null,
'utm_campaign' => $_POST['utm_campaign'] ?? null,
'utm_term' => $_POST['utm_term'] ?? null,
'utm_content' => $_POST['utm_content'] ?? null,
];
// отфильтрует значения по empty
$utms = array_filter($utms);
// отфильтрует только null
$utms = array_filter($utms, fn($val) => $vall !== null)
$array = [
[
"" => "что то не нужное",
"brand" => "Бренд",
"code" => "Артикул",
"price" => "цена",
"quantity" => "кол-во",
"name" => "нейм",
],
];
$filter = function ($value, $key) {
return !empty($key);
};
$result = array_map(function ($value) use ($filter) {
return array_filter($value, $filter, ARRAY_FILTER_USE_BOTH);
}, $array);