Output values of the array only if not empty or null

Output values of the array only if not empty or null

I am really new to php and do not know what I should look up to get this solved. I am trying to show only the values if the variable is not empty nor null.

I am really new to php and do not know what I should look up to get this solved. I am trying to show only the values if the variable is not empty nor null.

Within an array I assign:

$attributes [
'glutenfree'               => getPublicClassificationsDescription($classifications, ARTICLE_GLUTENFREE),
            'lactosefree'              => getPublicClassificationsDescription($classifications, ARTICLE_LACTOSEFREE),
            'flavouringfree'           => getPublicClassificationsDescription($classifications, ARTICLE_FLAVOURINGFREE),
            'corerange'                => getPublicClassificationsDescription($classifications, ARTICLE_CORERANGE),
            'engro'                    => getPublicClassificationsDescription($classifications, ARTICLE_ENGRO),
            'vegan'                    => getPublicClassificationsDescription($classifications, ARTICLE_VEGAN),
...
];

and a lot of other attributes more. I want the output that it is only printed to the CSV if it is not empty nor null.

Right now I get the result like this:

glutenfree=,lactosefree=,flavouringfree=,corerange=,engro=,vegan=No,...

The output I need is like everything that is empty/null should be gone but the ones with value should be there. In this example:

vegan=No,...

For example if I try with "empty" or "isset" it does not work and I get a blank page with no errors.

$glutenfree = getPublicClassificationsDescription($classifications, ARTICLE_GLUTENFREE);

$attributes [ if (!empty($glutenfree)) { 'glutenfree' => $glutenfree, 'lactosefree' => getPublicClassificationsDescription($classifications, ARTICLE_LACTOSEFREE), 'flavouringfree' => getPublicClassificationsDescription($classifications, ARTICLE_FLAVOURINGFREE), 'corerange' => getPublicClassificationsDescription($classifications, ARTICLE_CORERANGE), 'engro' => getPublicClassificationsDescription($classifications, ARTICLE_ENGRO), 'vegan' => getPublicClassificationsDescription($classifications, ARTICLE_VEGAN), ... ];


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

PHP Interview Questions with Solutions: Prepare for PHP Interview

Prepare for PHP Interviews. Set Variable With php.ini File. Logic & Output Behind PHP Code Segment. Class Concept, Error & Functions in PHP. Start PHP Now!

PHP Web Application Development Company

As a top **PHP Web Application Development Company in USA**[https://www.dataeximit.com/php-development-services/](https://www.dataeximit.com/php-development-services/ "https://www.dataeximit.com/php-development-services/"), we at Data EximIT have...

Advantages of Hiring PHP Developer for your Website Project

PHP - Hypertext pre-processor, a scripting language used by many people in developing web pages, but most of us are unaware even of the full form. To train someone and make them learn this whole language is as difficult and time-consuming as it is...