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

Which PHP Framework to choose in 2024

jQuery UI - Dialog - How to hide autofocus

HTML - How to add placeholder to dropdown (select) with selectpicker