Back to Hhvm

LinearSearch

hphp/hack/manual/apis/Classes/HH/Vector/linearSearch.md

latest1.1 KB
Original Source

:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::

Returns the index of the first element that matches the search value

Hack
public function linearSearch(
  mixed $search_value,
): int;

If no element matches the search value, this function returns -1.

Guide

Parameters

  • mixed $search_value - The value that will be searched for in the current Vector.

Returns

  • int - The key (index) where that value is found; -1 if it is not found.

Examples

basic-usage.hack
$v = Vector {'red', 'green', 'blue', 'yellow'};

// Prints 2
\var_dump($v->linearSearch('blue'));

// Prints -1 (since 'purple' is not in the Vector)
\var_dump($v->linearSearch('purple'));
<!-- HHAPIDOC -->