Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Component/Utility/Number.php \Drupal\Component\Utility\Number::intToAlphadecimal()
  2. 9 core/lib/Drupal/Component/Utility/Number.php \Drupal\Component\Utility\Number::intToAlphadecimal()

Generates a sorting code from an integer.

Consists of a leading character indicating length, followed by N digits with a numerical value in base 36 (alphadecimal). These codes can be sorted as strings without altering numerical order.

It goes: 00, 01, 02, ..., 0y, 0z, 110, 111, ... , 1zy, 1zz, 2100, 2101, ..., 2zzy, 2zzz, 31000, 31001, ...

Parameters

int $i: The integer value to convert.

Return value

string The alpha decimal value.

See also

\Drupal\Component\Utility\Number::alphadecimalToInt

2 calls to Number::intToAlphadecimal()
Comment::preSave in core/modules/comment/src/Entity/Comment.php
Acts on an entity before the presave hook is invoked.
NumberTest::testConversions in core/tests/Drupal/Tests/Component/Utility/NumberTest.php
Tests the alphadecimal conversion functions.

File

core/lib/Drupal/Component/Utility/Number.php, line 79

Class

Number
Provides helper methods for manipulating numbers.

Namespace

Drupal\Component\Utility

Code

public static function intToAlphadecimal($i = 0) {
  $num = base_convert((int) $i, 10, 36);
  $length = strlen($num);
  return chr($length + ord('0') - 1) . $num;
}