public function occurrences(string $needle): array
    {
        $offset = 0;
        $allPositions = [];

        while (($position = strpos($this->string, $needle, $offset)) !== false) {
            $offset = $position + 1;
            $allPositions[] = $position;
        }

        return $allPositions;
    }
public function occurrences(string $needle): array
    {
        $offset = 0;
        $allPositions = [];

        while (($position = strpos($this->string, $needle, $offset)) !== false) {
            $offset = $position + 1;
            $allPositions[] = $position;
        }

        return $allPositions;
    }
public function occurrences ( string $ needle ) : array { $ offset = 0 ; $ allPositions = [ ] ; while ( ( $ position = strpos ( $ this -> string , $ needle , $ offset ) ) !== false ) { $ offset = $ position + 1 ; $ allPositions [ ] = $ position ; } return $ allPositions ; }
Find all the positions of occurrences of the given needle in the string

@param string $needle The value to find in the string

@return array
Find all the positions of occurrences of the given needle in the string