Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Going through my entire $_SESSION array and removing null variables

Tags:

php

I've been doing some tests with $_SESSION variables and that left a lot of them set to NULL, but still existing. I can remove them one-by-one, but how can I just loop through the $_SESSION array and remove NULL variables quickly?

like image 502
AKor Avatar asked May 20 '26 20:05

AKor


1 Answers

You can use array_filter with a callback function that uses is_null:

$output = array_filter($input, function($val) { return !is_null($val); });
like image 76
Gumbo Avatar answered May 22 '26 08:05

Gumbo