Is there a function that will recursively traverse array values?

I have an array that can have several null or empty values ​​in it. Is there a PHP function that I can use to move this array to just find out if there is a value somewhere?

For instance:

[0]=>
[1]=>
[2]=> test

I would like to test against the total number of values, if any. count () will not work, because it is only part of this array, and it always returns 1, which is inaccurate.

Array
(
    [inputbox] => Array
        (
            [name] => Array
                (
                    [0] => New Text Document.txt  <------- This is what I need to test
                    [1] => 
                )

            [type] => Array
                (
                    [0] => text/plain
                )

            [tmp_name] => Array
                (
                    [0] => /var/tmp/phpLg2rFl
                    [1] => 
                )

            [error] => Array
                (
                    [0] => 0
                    [1] => 
                )

            [size] => Array
                (
                    [0] => 0
                    [1] => 
                )
        )
)
+3
source share
1 answer

I do not understand your question very well, but maybe you are looking array_filter()

array_filter($arr) , 2 test, count().


:

if (count(array_filter($arr)) > 0)
{
    echo '$arr has values';
}

, array_filter(), , false, , 0. , :

if (count(array_filter($arr, 'isset')) > 0)
{
    echo '$arr has values';
}

( ):

if (count(array_filter($arr, 'strlen')) > 0)
{
    echo '$arr has values';
}

Coalesce PHP.


, array_filter() ( $_FILES) :

if (count(array_filter($_FILES['inputbox']['name'], 'strlen')) > 0)
{
    echo count($_FILES['inputbox']['name']) . ' files';
    echo '<br />';
    echo count(array_filter($_FILES['inputbox']['name'], 'strlen')) . ' files set';
}
+2

Source: https://habr.com/ru/post/1730656/


All Articles