89 of 110 menu

PHP Remove Empty Array Elements

There are various ways to remove empty array elements. The example shows the most efficient one:

<?php $arr = ['', 'a', '', 'b', 'c']; $new_arr = array_diff($arr, ['']) var_dump($new_arr); ?>

Code execution result:

['a', 'b', 'c']
English
БеларускаяEspañolРусский
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline