PHP in_array() can't even match a single character. Strict is set to true.

Posted by solefald on Stack Overflow See other posts from Stack Overflow or by solefald
Published on 2010-05-01T05:35:48Z Indexed on 2010/05/01 5:37 UTC
Read the original article Hit count: 237

Filed under:
|
|
|

I've seen a million of these threads here already, and read through every single one already. Including some serious time Googling.

Nothing complicated. All I have to do is check if a single character in a loop matches my alphabet array.

print_r($alphabet); // all 26 letters

Array ( 
        [0] => a
        [1] => b
        [2] => c
        ...            
        [23] => x
        [24] => y
        [25] => z
 )

 print_r($emptyLetters); // dynamic array.

 Array ( 
        [0] => b
        [1] => s
 )

 foreach($alphabet as $letter):
 {
      echo $letter . '<br />' // Correctly prints out every letter from $alphabet.
      if(in_array($letter, $emptyLetters, true)):  // $strict is set
           // do something

      endif;

 }

What the hell is going on??? I do not understand what i am doing wrong.... I tried every combination and option possible, but for some reason even array_search() is bit working...

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays