public static PhpArray each(IPhpEnumerable array)
{
if (array == null)
{
//PhpException.ReferenceNull("array");
return null;
}
if (array.IntrinsicEnumerator.AtEnd)
return null;
var entry = array.IntrinsicEnumerator.Current;
array.IntrinsicEnumerator.MoveNext();
// dereferences result since enumerator doesn't do so:
var key = entry.Key;
var value = entry.Value; // PhpVariable.Dereference(entry.Value);
// creates the resulting array:
PhpArray result = new PhpArray(2);
result.Add(1, value);
result.Add("value", value);
result.Add(0, key);
result.Add("key", key);
// keys and values should be inplace deeply copied:
// TODO: result.InplaceCopyOnReturn = true;
return result;
}