A_Z_Listing_Grouping::alphabet_filter( string $alphabet )

Override the alphabet with grouped letters


Description


Parameters

$alphabet

(string) (Required) The alphabet to override.


Return

(string) the new grouped alphabet.


Source

File: classes/class-a-z-listing-grouping.php

	public function alphabet_filter( $alphabet ) {
		$headings = array();
		$letters  = mb_split( ',', $alphabet );
		$letters  = array_map( 'trim', $letters );

		$i = 0;
		$j = 0;

		$grouping = $this->grouping;

		$groups = array_reduce(
			$letters,
			function( $carry, $letter ) use ( $grouping, &$headings, &$i, &$j ) {
				if ( ! isset( $carry[ $j ] ) ) {
					$carry[ $j ] = $letter;
				} else {
					$carry[ $j ] = $carry[ $j ] . $letter;
				}
				$headings[ $j ][] = mb_substr( $letter, 0, 1 );

				if ( $i + 1 === $grouping ) {
					$i = 0;
					$j++;
				} else {
					$i++;
				}

				return $carry;
			}
		);

		$this->headings = array_reduce(
			$headings,
			function( $carry, $heading ) {
				$carry[ mb_substr( $heading[0], 0, 1 ) ] = $heading;
				return $carry;
			}
		);

		return join( ',', $groups );
	}

Changelog

Changelog
Version Description
2.0.0 Introduced.

More Information

You are currently logged out. To view tickets you must first login.

I have read and understood the Terms of Service


User Contributed Notes

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.