4

Is in_array() function in php multibyte safe?

If not ,how can i make it so?

The php.net multibyte reference lists mb_stristr() but it accepts a string , not an array as haystack .

My haystack = array of strings and needle = string.

Shi
  • 4,178
  • 1
  • 26
  • 31
zacurry
  • 876
  • 3
  • 12
  • 25

1 Answers1

2

Since I could not find any built in PHP solution, I did as @FirstOne suggested.

/**
 * @return bool true if needle is found in haystack, false otherwise
 */
public function custom_mb_in_array($_needle, array $_hayStack) {
    foreach ($_hayStack as $value) {
        if (mb_strtolower($value) === mb_strtolower($_needle)) {
            return true;
        }
    }
    return false;   
}
Callum Watkins
  • 2,844
  • 4
  • 29
  • 49
zacurry
  • 876
  • 3
  • 12
  • 25