I'm trying to do the in_array inside of an If else statement. Where it checks if the value exists in an array or not.
Here's how I get the array values from ajax to controller
$data_days = $request->dataDays;
Sample output: 1,2,3,4,5,6,7
If the user didn't check monday and the rest of the days are checked it will return the array like this 2,3,4,5,6,7
These numbers are the number of days
1 = Monday
2 = Tuesday and so on..
and it comes from multiple checkboxes.
Well it works fine when the value matches inside of an array. But when the value isn't exists inside of an array it returns an error which says
in_array() expects parameter 2 to be array, null given because the value that I'm matching with my array isn't exists or null
if (in_array('1', $data_days, true)){
$message = "exists";
}
else{
$message = "doesn't exists!";
}
If there's no 1 value inside of an array it should return the doesn't exists! where as of now it just give me an error like this
in_array() expects parameter 2 to be array, null given
!empty()&in_array()should fix the issue.