Answer the question
In order to leave comments, you need to log in
Why does in_array only see the first element in the loop?
There is an array that stores the time in the HH:MM format. Array ( [0] => 16:30 [1] => 17:00 )
If you use the Then function in the loop,
it sees the first element and returns TRUE , but if you try to check the second element of the array, it does not return anything. Why? And how to fix it?in_array('16:30', $array);
in_array('17:00', $array);
Answer the question
In order to leave comments, you need to log in
The problem is that the string from which the array was created at the end contains (most likely) a newline, so the second (aka last element) contains non-printable characters that interfere with the comparison.
will solve the problem
Add third argument to function
https://www.php.net/manual/ru/function.in-array.php
Third argument true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question