HH\Pair::slice

Returns a subset of the current Pair starting from a given key up to, but not including, the element at the provided length from the starting key

Description

public function slice(
  int $start,
  int $len,
): ImmVector<mixed>;

$start is 0-based. $len is 1-based. So slice(0, 2) would return the elements at key 0 and 1 (all of the current Pair elements).

Parameters

  • $start - The starting key of the current Pair to begin the returned ImmVector.
  • $len - The length of the returned ImmVector.

Return Values

Examples

<?hh

namespace Hack\UserDocumentation\API\Examples\Pair\Slice;

$p = Pair {'foo', -1.5};

// Get an ImmVector of both values
var_dump($p->slice(0, 2));

// Get an ImmVector of the first value
var_dump($p->slice(0, 1));

// Get an ImmVector of the second value
var_dump($p->slice(1, 1));
Output
object(HH\ImmVector)#2 (2) {
  [0]=>
  string(3) "foo"
  [1]=>
  float(-1.5)
}
object(HH\ImmVector)#2 (1) {
  [0]=>
  string(3) "foo"
}
object(HH\ImmVector)#2 (1) {
  [0]=>
  float(-1.5)
}