Library
Class

Library\Helper\Number

class Number

Number helper

As for all helpers, all methods are statics.

For convenience, the best practice is to use:

use Library\Helper\Number as NumberHelper;

Methods

static bool isOdd(int $val = null)

Test if an integer is an "odd number"

static bool isEven(int $val = null)

Test if an integer is an "even number"

static bool isPrime(int $val = null)

Test if an integer is a "prime number"

static int getFibonacciItem(int $val = null)

Get the $val element of the Fibonacci suite

static int getLuhnKey(int $val = null)

Luhn formula: get the Luhn digit of an integer

static bool isLuhn(int $val = null)

Check that the last number in a suite is its Luhn key

static int getSumOfDigits($val $val = null)

Calculate the sum of the digits of a number (its absolute entire value)

static bool isSelfDescribing($val $val = null)

Test if a number is "self-describing":

static bool isJollyJumperSeries(array $items = array())

Test if a series of numbers is a "Jolly Jumper":

Details

at line 46
static public bool isOdd(int $val = null)

Test if an integer is an "odd number"

Parameters

int $val

Return Value

bool

at line 60
static public bool isEven(int $val = null)

Test if an integer is an "even number"

Parameters

int $val

Return Value

bool

at line 74
static public bool isPrime(int $val = null)

Test if an integer is a "prime number"

Parameters

int $val

Return Value

bool

at line 99
static public int getFibonacciItem(int $val = null)

Get the $val element of the Fibonacci suite

Parameters

int $val

Return Value

int

at line 123
static public int getLuhnKey(int $val = null)

Luhn formula: get the Luhn digit of an integer

7992739871 => 3

Parameters

int $val

Return Value

int

See also

<http://en.wikipedia.org/wiki/Luhn_algorithm>

at line 154
static public bool isLuhn(int $val = null)

Check that the last number in a suite is its Luhn key

Parameters

int $val The number to check INCLUDING Luhn's key at last

Return Value

bool

at line 169
static public int getSumOfDigits($val $val = null)

Calculate the sum of the digits of a number (its absolute entire value)

Parameters

$val $val

Return Value

int

at line 195
static public bool isSelfDescribing($val $val = null)

Test if a number is "self-describing":

assuming digit positions are labeled 0 to N-1, the digit in each position is equal to the number of times that digit appears in the number

2020 => true 22 => false 1210 => true

Parameters

$val $val

Return Value

bool

at line 220
static public bool isJollyJumperSeries(array $items = array())

Test if a series of numbers is a "Jolly Jumper":

A sequence of n > 0 integers where the absolute values of the differences between successive elements take on all possible values 1 through n - 1.

Parameters

array $items

Return Value

bool