-
-
Notifications
You must be signed in to change notification settings - Fork 13
IEnumerable.elementAtOrDefault() method
Marcel Kloubert edited this page Sep 25, 2015
·
3 revisions
Returns a value at a specific position or a default value if not found (s. ElementAtOrDefault()).
public function elementAtOrDefault(int $index
[, mixed $defValue = null ]) : mixed;
Name | Type | Description |
---|---|---|
$index | int | The zero-based index. |
$defValue | mixed | [OPTIONAL] The value to return if element was not found. |
The zero based index.
Is returned if element was not found.
The value / default value.
use \System\Linq\Enumerable;
$seq = Enumerable::fromValues(1, 2, 3);
// 2
$res = $seq->elementAtOrDefault(1, 'TM');
use \System\Linq\Enumerable;
$seq = Enumerable::fromValues();
// 'TM'
$res = $seq->elementAtOrDefault(1, 'TM');
use \System\Linq\Enumerable;
$seq = Enumerable::fromValues(1, 2, 3);
// (false)
$res = $seq->elementAtOrDefault(3, false);