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), ... ];


php arrays

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire PHP Developer

Looking to develop a PHP based website from scratch or revamp your existing website? **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")** has always been an industry leader for companies and business owners looking to hire...

PHP Array Count Example | PHP count() Function Tutorial

PHP Array Count Example | PHP count() Function Tutorial. PHP Array count() method returns the number of elements in an array and multidimensional array.

PHP Array Sum Example | PHP array_sum() Function Tutorial

PHP Array Sum Example | PHP array_sum() Function Tutorial. The array_sum() function returns the sum of all the values in the array.

PHP Array Reduce Example | PHP array_reduce() Function Tutorial

PHP array_reduce() is an inbuilt function that sends the values in the array to a user-defined function and returns a string. PHP array reduce example.

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...