public static PhpArray array_flip(PhpArray array)
{
if (array == null)
{
//PhpException.ArgumentNull("array");
//return null;
throw new ArgumentNullException();
}
PhpArray result = new PhpArray(array.Count);
var iterator = array.GetFastEnumerator();
while (iterator.MoveNext())
{
var entry = iterator.Current;
// dereferences value:
var val = entry.Value.GetValue();
switch (val.TypeCode)
{
case PhpTypeCode.Int32:
case PhpTypeCode.Long:
case PhpTypeCode.String:
case PhpTypeCode.WritableString:
var askey = val.ToIntStringKey();
result[askey] = PhpValue.Create(entry.Key);
break;
default:
// PhpException.Throw(PhpError.Warning, LibResources.GetString("neither_string_nor_integer_value", "flip"));
throw new ArgumentException();
}
}
// no need to deep copy because values are ints/strings only (<= keys were int/strings only):
return result;
}