-
-
Notifications
You must be signed in to change notification settings - Fork 13
IEnumerable.toArray() method
Marcel Kloubert edited this page Sep 25, 2015
·
4 revisions
Converts that sequence to a new PHP array (s. ToArray()).
public function toArray([ callable $keySelector = null ]) : array;| Name | Type | Description |
|---|---|---|
| $keySelector | [[callable | Callable]] |
The callable that produces the key for an item.
function (mixed $key, mixed $item, IIndexedItemContext $ctx);The original key of the current item.
The current item.
The item context for $item.
The new array.
use \System\Linq\Enumerable;
$seq = Enumerable::create(['a' => 239, 'b' => 5979, 'c' => 1]);
// [0] => 239
// [1] => 5979
// [2] => 1
$arr = $seq->toArray();
// (true)
$ia = is_array($arr);use \System\Linq\Enumerable;
$seq = Enumerable::create(['a' => 239, 'b' => 5979, 'c' => 1]);
// ['A'] => 239
// ['B'] => 5979
// ['C'] => 1
$arr = $seq->toArray('$key => strtoupper($key)');use \System\Linq\Enumerable;
$seq = Enumerable::create(['A' => 239, 'B' => 5979, 'C' => 1]);
// ['a'] => 239
// ['b'] => 5979
// ['c'] => 1
$arr = $seq->toArray(function ($key) {
return strtolower($key);
});