Gets the index of the key containing searched reference.
Returnes $this->forkRate if reference is in 'last-reference' of this node.
Returnes null if reference is not found in this node.

@return int|null
@param string $needle
515277
public function getIndexByReference($needle)
    {
    #    $this->checkValue($needle);
        if ($needle === $this->getLastReference()) {
            return $this->forkRate;
        }
        $index = 0;
        while (1) {
            $reference = substr($this->data, $index*$this->keyLength*3, $this->keyLength);
            if (trim($reference, "\0")==='' || $index === $this->forkRate) {
                return null;
            }
            if ($needle === $reference) {
                return $index;
            }
            $index++;
        }
    }
1034276
protected function findLine($key)
    {
        $parsedKey   = null;
        $parsedValue = null;

        foreach ($this->lines as $index => $line) {
            $parseOk = $this->parseEnvLine($line, $parsedKey, $parsedValue);
            if ($parseOk && $key === $parsedKey) {
                return $index;
            }
        }

        return -1;
    }
975820
public static function arraySearchGetValue($needle, array $haystack)
    {
        $lcNeedle = strtolower($needle);

        foreach ($haystack as $value) {
            if ($lcNeedle == strtolower($value)) {
                return $value;
            }
        }

        return null;
    }
842302
private static function arraySearch(string $needle, array $haystack): string
    {
        foreach ($haystack as $key => $value) {
            if ($needle === $value || (is_array($value) && self::arraySearch($needle, $value) !== '')) {
                return $key;
            }
        }

        return '';
    }
1324042
protected function searchNamespace($needle, $haystack)
    {
        $needle = realpath($needle);
        $haystack = array_map('realpath', $haystack);

        $key = array_search($needle, $haystack);

        return is_string($key) ? trim($key, '\\') : null;
    }
255636
public function percentage(string $needle) : float
    {
        $freqDist = freq_dist($this->getTokens());
        return $freqDist->getKeyValuesByFrequency()[$needle] / $freqDist->getTotalTokens();
    }
31895
public function Item( $index )
	{
		if ( $this->getCount() <= $index && ! $this->_done )
		{
			$count = $this->getCount();
			while ( ! $this->_done && ( $count <= $index))
			{
				if ( $this->_iter->MoveNext() )
				{
					/**
					 * @var XmlNode $node
					 */
					$node = $this->GetNode( $this->_iter->getCurrent() );
					if ( ! is_null( $node ) )
					{
						$this->_list[] = $node;
						$count++;
					}
				}
				else
					$this->_done = true;
			}
		}
		if ( $index >= 0 && count( $this->_list ) > $index )
			return $this->_list[ $index ];
		return null;
	}
803148
public function findAll(string $needle) : array
    {
        $lastPos = 0;
        $positions = [];
        $needle = strtolower($needle);
        $text = strtolower($this->getText());
        $needleLength = strlen($needle);
        while (($lastPos = stripos($text, $needle, $lastPos))!== false)
        {
            $positions[] = $lastPos;
            $lastPos += $needleLength;
        }
        return $positions;
    }
1023699
public function getNodeIndex($nodeId)
    {
        return isset($this->nodeMap[$nodeId]) ? $this->nodeMap[$nodeId]['index'] : null;
    }
30114
public static function indexOf($string, $needle, $strict = true, $offset = 0) {
        if ($strict) {
            return mb_strpos($string, $needle, $offset);
        }

        return mb_stripos($string, $needle, $offset);
    }
838909
function(needle) {
        if (arr.indexOf) {
          return arr.indexOf(needle);
        } else {
          for (var i=0, length=arr.length; i<length; i++) {
            if (arr[i] === needle) { return i; }
          }
          return -1;
        }
    }
521334
public function contains($needle, ?string $key = null) : bool
    {
        $value = $this->get($key);

        if (!is_array($value)) {
            throw new InvalidArgumentException(
                'method contains() should be called on array'
            );
        }

        return in_array($needle, $value);
    }
58536
public function offsetGet($offset)
    {
        $index = $this->getKeyIndex($offset);

        if ($index >= 0) {
            return $this->values[$index];
        }

        return null;
    }
1215055
function _findIndex(haystack, needle) {
            if (angular.isUndefined(haystack) || haystack.length === 0) {
                return -1;
            }

            for (var i = 0, len = haystack.length; i < len; i++) {
                if (haystack[i] === needle) {
                    return i;
                }
            }

            return -1;
        }
887610
public static function getStartBeforeLast(string $haystack, string $needle)
    {
        $end = self::getEndAfterLast($haystack, $needle);
        $length = -1 * (strlen($end) + strlen($needle));
        return substr($haystack, 0, $length);
    }
921097
protected function substitute($keys, $needle, $reference)
    {

        foreach($keys as $srch=>$replc){

            //$srch = str_replace(array("(",")","[","]"), array('\(','\)','\[','\]'));
            if(preg_match("/\((?<idx>\d+)\)/", $srch, $match)){
                $idx = $match['idx'];
                $regr = "/\({$idx}\)(?<val>.*?)\({$idx}\)/";
                if(preg_match($regr, $reference, $match)){
                    $replc = "%".$match['val']."%";
                }else{
                    //$regr = "/\({$idx}\)(.*?)\({$idx}\)/";
                    $replc = "%$1%";
                };
                $regr = "/\(\s?{$idx}\s?\)(.*?)\(\s?{$idx}\s?\)/";
            }else{
                if(preg_match("/\[(?<idx>\d+)\]/", $srch, $match)){
                    $idx = $match['idx'];
                    $regr = "/\[\s?{$idx}\s?\]/";
                }else{
                    die("error in substitute $srch=>$replc");
                }
            }
            $needle = preg_replace($regr, $replc, $needle);
        }

        return $needle;
    }
119860
protected function findSettingByName($haystack, $needle)
    {
        foreach ($haystack as $setting) {
            if ($setting->getName() === $needle) {
                return $setting;
            }
        }
    }