NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle+0 views

What will be the output when array_search() is used in an if condition?

Practice

Asked at

AI answer

array_search() returns the key of the found element or false if the element is not found. In an if condition, the key 0 is treated as false, so the condition will not be met for the first element. Check the result strictly: if (array_search($value, $array) !== false).},