Python has a synthax to chain comparison operators. For example:
if x > y > z:
print('foo')
if x < y < z:
print('bar')
if x == y == z:
print('baz')
But PHP doesn't offer a syntax like this.
So I implemented a few functions to emulate this kind of comparison.
To check if the items in the array are ascending, like x < y < z
in Python:
if (array_is_asc([$x, $y, $z]))
// ...
// To accept consecutive equal values (like `x <= y <= z`).
if (array_is_asc([$x, $y, $y, $z], eq: true))
// ...
// It makes the code cleaner when used with multiple values
// (althoug less efficient).
if (array_is_asc([$kMin, $x, $y, $kMid, $z, $w, $kMax]))
// ...
To check if the items in the array are descending, like x > y > z
in Python:
if (array_is_desc([$x, $y, $z]))
// ...
// To accept consecutive equal values (like `x >= y >= z`).
if (array_is_desc([$x, $y, $y, $z], eq: true))
// ...
To check if all items in an array equals to a value, like x == y == z == 1
in Python:
if (array_all_eq_val([$x, $y, $z], 1))
// ...
// To use the identical operator `===`
if (array_all_eq_val([$x, $y, $z], 1, strict: true))
// ...
To check if all items in an array are the same, like x == y == z
in Python:
if (array_all_eq([$x, $y, $z]))
// ...
// To use the indentical operator `===`
if (array_all_eq([$x, $y, $z], strict: true))
// ...
To check if all items in an array are unique, like len(x) == len(set(x))
in Python:
if (array_all_unique([$x, $y, $z]))
// ...
// To use the identical operator `===`
if (array_all_unique([$x, $y, $z], strict: true))
// ...
Use as you wish, don't blame me.