-
-
Notifications
You must be signed in to change notification settings - Fork 13
IEnumerable.defaultIfEmpty() method
Marcel Kloubert edited this page Sep 25, 2015
·
3 revisions
Returns the elements of the sequence or a sequence with default values if the current sequence is empty (s. DefaultIfEmpty()).
public function defaultIfEmpty([mixed $val1 [, mixed $... ]]) : IEnumerable;
Name | Type | Description |
---|---|---|
$... | mixed | [OPTIONAL] The list of default values. |
The new sequence.
use \System\Linq\Enumerable;
$seq1 = Enumerable::fromValues(1, 2, 3);
$seq2 = Enumerable::fromValues();
// [1, 2, 3]
$a1 = $seq1->defaultIfEmpty('TM', 'MK')
->toArray();
// ['TM', 'MK']
$a2 = $seq2->defaultIfEmpty('TM', 'MK')
->toArray();