public static PhpValue array_search(PhpValue needle, PhpArray haystack, bool strict = false)
{
// result needn't to be deeply copied because it is a key of an array //
if (haystack == null)
{
// TODO: PhpException.ArgumentNull("haystack");
return PhpValue.False;
}
// using operator ===:
if (strict)
{
using (var enumerator = haystack.GetFastEnumerator())
while (enumerator.MoveNext())
{
// TODO: dereferences value (because of StrictEquality operator):
if (needle.StrictEquals(enumerator.CurrentValue))
return PhpValue.Create(enumerator.CurrentKey);
}
}
else
{
// using operator ==:
using (var enumerator = haystack.GetFastEnumerator())
while (enumerator.MoveNext())
{
// note: comparator manages references well:
if (needle.Equals(enumerator.CurrentValue))
return PhpValue.Create(enumerator.CurrentKey);
}
}
// not found:
return PhpValue.False;
}