PHP - How to explode empty string with empty array

When you try to explode empty string, you get not empty array, as we would have assumption, but array with one element with blank string. PHP says it is not a bug.

So, we need to find a way how to avoid this behavior. As we don`t want to have any element in array after exploding empty string. We want to have empty array as well, obviously.

We can use "array_filter" function to remove empty element in array.

Example:

$correctArray = array_filter(explode(';', ''));

Comments

Popular posts from this blog

CSS Как прикрепить слой (div) к краю

MySQL - How to add JSON column type

Как сделать заголовок модуля активной ссылкой в Joomla 1.5