Search code examples
phparrayswordpressfilewarnings

array_filter() expects parameter 1 to be array in PHP


i have an issue with a line for several days.

Here is my code :

$files = array();
$count = count(array_filter($_FILES['fichier']['name']));
echo $count;

for($i=0;$i<$count;$i++){
    array_push($files, $_FILES['fichier']['tmp_name'][$i]);
}

This code is in a form, but when i submit my form, i have this error message :

Warning: array_filter() expects parameter 1 to be array, null given in...

This part of code works in FR version, but when i tried to copy/paste in EN version, it doesn't work.

I've tried everything, nothing happens.

Thanks.

EDIT :

var_dump(array_filter($_FILES['fichier']['name']));

return me this :

NULL

when i'm trying to upload 1 or many files.


Solution

  • I think when you see this error you can use this:

    <td>{{ is_array($client->phone) ? implode($client->phone, '-') : $client->phone }}</td>