Calamity Jane Calamity Jane - 3 months ago 6x
PHP Question

Weird php in_array behaviour

I have trouble with the result of in_array. It is not like i would have expected and as I understand the manual.

Simple test:

$_aOperatorsOneOptin = array('DE-010', 'DE-005');

$bMatchPaymentOperator = in_array(0 , $_aOperatorsOneOptin);

echo 'found';

I would expect that I would get no result with this, but $bMatchPaymentOperator is true!

I would expect that

$bMatchPaymentOperator = in_array('DE-010' , $_aOperatorsOneOptin);

is true , which it is.
But why oh why is the upper statement true?

I have tested this behaviour on php 5.6 and php 5.5

Med Med

Use third parameter of in_array to force strict match


$_aOperatorsOneOptin = array('DE-010', 'DE-005');

$bMatchPaymentOperator = in_array(0 , $_aOperatorsOneOptin, true);

if($bMatchPaymentOperator == true)
    echo 'found';