Let’s clean some data: $data = ['apple', '', null, 'banana', false]; $clean = array_filter($data); // Result: ['apple', 'banana'] By default, array_filter() removes falsey values: null, false, ‘’, 0, etc. But you can pass your own logic: $even = array_filter([1, 2, 3, 4], fn($n) => $n % 2 === 0); // Result: [1 => 2, 3 => 4]
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter