array_filter() expects parameter 1 to be array in PHP
14,041
I think when you see this error you can use this:
<td>{{ is_array($client->phone) ? implode($client->phone, '-') : $client->phone }}</td>
Author by
Tweakdev
Updated on June 27, 2022Comments
-
Tweakdev almost 2 years
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.
-
Romeo Sierra almost 6 years
array_filter($_FILES['fichier']['name'])
returns a string containing the file name that has been uploaded under the fieldfichier
. You edit the question to elaborate your requirement, may be we could help. What is it that you cant this$count
to be? -
u_mulder almost 6 years
var_dump($_FILES)
-
Tweakdev almost 6 years$count return me 0 everytime even if i'm uploading 1 or many files. This part of code works good in FR version, i can't understand the problem.
-
Tweakdev almost 6 years@u_mulder var_dump($_FILES) returns to me : array(0) { } , even if i'm uploading two files, for example
-
u_mulder almost 6 yearsSo the real problem is that
$_FILES
empty. Check your form. Do you haveenctype
attribute for a form? -
Tweakdev almost 6 yearsyou're right @u_mulder , i just put a enctype attribute on my form, then i put name="file[]" on my input field for multiple files, and it works. Thanks for your time.
-