php - In a Twig template {{0 in ['a', 'b', '99']}} returns 1. WHY?
Get the solution ↓↓↓Solution:
PHP's type coercion for comparisons goes to integers when necessary. You're checking if an integer is in the array.(int) 'a'
is coerced to0
for this comparison. So0
is seen as being in the array.
To avoid this, you can usein_array
with the strict option:
in_array('0', ['a', 'b', '99'], true)
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: php undefined array key
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.