Use the array_filter of function in php to get rid of code sharing for multidimensional null values

  • 2020-05-24 05:17:10
  • OfStack

In fact, we can use the array_filter function to easily remove the multidimensional null value, but the subscript of the array has not changed. Here is an example:
< ?php
$array = array(
0 = > 'the elder brother of the deep,
1 = > false,
2 = > 1,
3 = > null,
4 = > '',
5 = > 'https://www.ofstack.com',
6 = > '0'
);
print_r(array_filter($array));
? >
The output result of the above code is:
Array
(
[0] = > The elder brother of the deep
[2] = > 1
[5] = > https://www.ofstack.com
)
This eliminates the null or null or false values to avoid bugs!

Related articles: