Ds\Map::slice
(PECL ds >= 1.0.0)
Ds\Map::slice — Returns a subset of the map defined by a starting index and length.
Описание
$index
[, array $length
] )
Returns a subset of the map defined by a starting index
and length
.
Список параметров
-
index
-
The index at which the range starts.
If positive, the range will start at that index in the map. If negative, the range will start that far from the end.
-
length
-
If a length is given and is positive, the resulting map will have up to that many pairs in it. If a length is given and is negative, the range will stop that many pairs from the end. If the length results in an overflow, only pairs up to the end of the map will be included. If a length is not provided, the resulting map will contain all pairs between the index and the end of the map.
Возвращаемые значения
A subset of the map defined by a starting index and length.
Примеры
Пример #1 Ds\Map::slice() example
<?php
$map = new \Ds\Map(["a" => 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5]);
// Slice from 2 onwards
print_r($map->slice(2)->toArray());
// Slice from 1, for a length of 3
print_r($map->slice(1, 3)->toArray());
// Slice from 1 onwards
print_r($map->slice(1)->toArray());
// Slice from 2 from the end onwards
print_r($map->slice(-2)->toArray());
// Slice from 1 to 1 from the end
print_r($map->slice(1, -1)->toArray());
?>
Результатом выполнения данного примера будет что-то подобное:
Array ( [c] => 3 [d] => 4 [e] => 5 ) Array ( [b] => 2 [c] => 3 [d] => 4 ) Array ( [b] => 2 [c] => 3 [d] => 4 [e] => 5 ) Array ( [d] => 4 [e] => 5 ) Array ( [b] => 2 [c] => 3 [d] => 4 )
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения, относящиеся к переменным и типам
- Data Structures
- Ds\Map::allocate
- Ds\Map::apply
- Ds\Map::capacity
- Ds\Map::clear
- Ds\Map::__construct
- Ds\Map::copy
- Ds\Map::count
- Ds\Map::diff
- Ds\Map::filter
- Ds\Map::first
- Ds\Map::get
- Ds\Map::hasKey
- Ds\Map::hasValue
- Ds\Map::intersect
- Ds\Map::isEmpty
- Ds\Map::jsonSerialize
- Ds\Map::keys
- Ds\Map::ksort
- Ds\Map::ksorted
- Ds\Map::last
- Ds\Map::map
- Ds\Map::merge
- Ds\Map::pairs
- Ds\Map::put
- Ds\Map::putAll
- Ds\Map::reduce
- Ds\Map::remove
- Ds\Map::reverse
- Ds\Map::reversed
- Ds\Map::skip
- Ds\Map::slice
- Ds\Map::sort
- Ds\Map::sorted
- Ds\Map::sum
- Ds\Map::toArray
- Ds\Map::union
- Ds\Map::values
- Ds\Map::xor
Коментарии
404 Not Found