简体   繁体   中英

Remove all array values with specific condition

I am getting bellow array output and I want to remove array only having this [name] => and [size] => 0 .

Current Array:

Array
(
    [0] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

    [1] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

    [2] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

    [3] => Array
        (
            [name] => Penguins.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/phpozs13E
            [error] => 0
            [size] => 777835
        )

    [4] => Array
        (
            [name] => Tulips.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/phpq66c41
            [error] => 0
            [size] => 620888
        )

    [5] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

)

And I want this Output

Array
(
    [0] => Array
        (
            [name] => Penguins.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/phpozs13E
            [error] => 0
            [size] => 777835
        )

    [1] => Array
        (
            [name] => Tulips.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/phpq66c41
            [error] => 0
            [size] => 620888
        )
)

It's simpler than that; you want the file uploads without an error; ie

$results = array_filter($_FILES, function($file) {
    return $file['error'] === 0;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM