-
-
Notifications
You must be signed in to change notification settings - Fork 13
IEnumerable.sequenceEqual() method
Marcel Kloubert edited this page Apr 11, 2023
·
12 revisions
Checks if the items of that sequence are all equal with the items of another one (s. SequenceEqual()).
public function sequenceEqual(sequence $second
[, equality_comparer $equalityComparer = null
[, equality_comparer $keyEqualityComparer = null ]]) : bool;| Name | Type | Description |
|---|---|---|
| $second | sequence | The other sequence. |
| $equalityComparer | equality_comparer | [OPTIONAL] The equality comparer to use. |
| $keyEqualityComparer | equality_comparer | [OPTIONAL] The equality comparer for the keys to use. |
The other sequence.
The comparer that checks if two elements are the same.
The comparer that checks if the keys of two elements are the same.
If that value is NULL, the keys will NOT be compared.
TRUE if sequences and its contents are equal; otherwise FALSE.
use \System\Linq\Enumerable;
$seq1_L = Enumerable::fromValues(1, 2, 3);
$seq1_R = Enumerable::fromValues(1, 2, 3);
$seq2_L = Enumerable::fromValues(1, 2, 3);
$seq2_R = Enumerable::fromValues(1, 2);
$seq3_L = Enumerable::fromValues(1, 2, 3);
$seq3_R = Enumerable::fromValues('1', '2', '3');
$seq4_L = Enumerable::fromValues(1, 2, 3);
$seq4_R = Enumerable::fromValues(2, 1, 3);
// (true)
$a1 = $seq1_L->sequenceEqual($seq1_R);
// (false)
$a2 = $seq2_L->sequenceEqual($seq2_R);
// (true)
$a3 = $seq3_L->sequenceEqual($seq3_R);
// (false)
$a4 = $seq4_L->sequenceEqual($seq4_R);use \System\Linq\Enumerable;
$comparer = '($x, $y) => (float)$x == ((float)$y / 10.0)';
$seq1_L = Enumerable::fromValues(1, 2, 3);
$seq1_R = Enumerable::fromValues(10, 20, 30);
$seq2_L = Enumerable::fromValues(1, 2, 3);
$seq2_R = Enumerable::fromValues(10, 20);
$seq3_L = Enumerable::fromValues(1, 2, 3);
$seq3_R = Enumerable::fromValues('10', '20', '30');
$seq4_L = Enumerable::fromValues(1, 2, 3);
$seq4_R = Enumerable::fromValues(20, 10, 30);
// (true)
$a1 = $seq1_L->sequenceEqual($seq1_R, $comparer);
// (false)
$a2 = $seq2_L->sequenceEqual($seq2_R, $comparer);
// (true)
$a3 = $seq3_L->sequenceEqual($seq3_R, $comparer);
// (false)
$a4 = $seq4_L->sequenceEqual($seq4_R, $comparer);use \System\Linq\Enumerable;
$comparer = function($x, $y) {
return (float)$x == ((float)$y / 10.0);
};
$seq1_L = Enumerable::fromValues(1, 2, 3);
$seq1_R = Enumerable::fromValues(10, 20, 30);
$seq2_L = Enumerable::fromValues(1, 2, 3);
$seq2_R = Enumerable::fromValues(10, 20);
$seq3_L = Enumerable::fromValues(1, 2, 3);
$seq3_R = Enumerable::fromValues('10', '20', '30');
$seq4_L = Enumerable::fromValues(1, 2, 3);
$seq4_R = Enumerable::fromValues(20, 10, 30);
// (true)
$a1 = $seq1_L->sequenceEqual($seq1_R, $comparer);
// (false)
$a2 = $seq2_L->sequenceEqual($seq2_R, $comparer);
// (true)
$a3 = $seq3_L->sequenceEqual($seq3_R, $comparer);
// (false)
$a4 = $seq4_L->sequenceEqual($seq4_R, $comparer);