public static PhpArray preg_grep(Context ctx, string pattern, PhpArray input, int flags = 0)
{
if (input == null)
{
return null;
}
var result = new PhpArray(input.Count);
if (input.Count != 0)
{
var regex = new PerlRegex.Regex(pattern);
var enumerator = input.GetFastEnumerator();
while (enumerator.MoveNext())
{
var str = enumerator.CurrentValue.ToStringOrThrow(ctx);
var m = regex.Match(str);
// move a copy to return array if success and not invert or
// not success and invert
if (m.Success ^ (flags & PREG_GREP_INVERT) != 0)
{
result.Add(enumerator.CurrentKey, enumerator.CurrentValue.DeepCopy());
}
}
}
//
return result;
}