public static PhpArray array_count_values(PhpArray array)
{
if (array == null)
{
//PhpException.ArgumentNull("array");
//return null;
throw new ArgumentNullException();
}
PhpArray result = new PhpArray();
var iterator = array.GetFastEnumerator();
while (iterator.MoveNext())
{
// dereferences value:
var val = iterator.CurrentValue.GetValue();
IntStringKey askey;
switch (val.TypeCode)
{
case PhpTypeCode.Int32:
case PhpTypeCode.Long:
case PhpTypeCode.String:
case PhpTypeCode.WritableString:
askey = val.ToIntStringKey();
break;
default:
// TODO: PhpException.Throw(PhpError.Warning, LibResources.GetString("neither_string_nor_integer_value", "count"));
throw new ArgumentException();
}
var countval = result[askey].ToLong(); // 0 for nonexisting entry
result[askey] = PhpValue.Create(countval + 1L);
}
// no need to deep copy (values are ints):
return result;
}