public static PhpArray array_filter(Context ctx /*, caller*/, PhpArray array, IPhpCallable callback)
{
if (array == null)
{
//PhpException.ArgumentNull("array");
//return null;
throw new ArgumentNullException(nameof(array));
}
if (callback == null)
{
//PhpException.ArgumentNull("callback");
//return null;
throw new ArgumentNullException(nameof(callback));
}
var result = new PhpArray();
var args = new PhpValue[1];
var iterator = array.GetFastEnumerator();
while (iterator.MoveNext())
{
var entry = iterator.Current;
// no deep copying needed because it is done so in callback:
args[0] = entry.Value;
// adds entry to the resulting array if callback returns true:
if (callback.Invoke(ctx, args).ToBoolean())
{
result.Add(entry);
}
}
// values should be inplace deeply copied:
//result.InplaceCopyOnReturn = true;
return result;
}