Download the PHP package alfetahe/digitalroot without Composer
On this page you can find all versions of the php package alfetahe/digitalroot. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alfetahe/digitalroot
More information about alfetahe/digitalroot
Files in alfetahe/digitalroot
Package digitalroot
Short Description Library for getting digital root from numbers and letters.
License MIT
Homepage https://github.com/alfetahe/digitalroot
Informations about the package digitalroot
digitalRoot
PHP library for calculating the digital root of numbers and letters.
The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This continues as long as necessary to obtain a single digit.
Letters are supported too. By default each letter carries its position value on the Pythagorean chart (A=1 … I=9, J=1 … R=9, S=1 … Z=8), and you can override that with your own map by passing an array as the second parameter to any of the exposed functions.
Requirements
- PHP 8.2 or newer
Install
Via Composer:
Usage examples
Default letter values
| Value | Letters |
|---|---|
| 1 | A J S |
| 2 | B K T |
| 3 | C L U |
| 4 | D M V |
| 5 | E N W |
| 6 | F O X |
| 7 | G P Y |
| 8 | H Q Z |
| 9 | I R |
Behaviour notes
- Input is taken as a string. Anything that is not
0-9ora-zA-Zis stripped before the calculation, so"a,..,b"is treated as"ab". - Letters are case insensitive.
- Empty input, and input that reduces to nothing, has a digital root of
0. - If you pass your own letter map and the input contains a letter the map does not define, an
InvalidArgumentExceptionis thrown rather than the letter silently counting as zero. getdigitalRootBulk()keys its result by the input value. Because these are PHP array keys, duplicate inputs collapse into a single entry and numeric strings become integer keys. UsegetDigitalRoot()in your own loop if you need one result per input, in order.
Testing
License
MIT. See LICENSE.