\AiUtil

Utility functions to make writing code easier.

Summary

Methods
Properties
Constants
__construct()
mustBeArray()
mustBeIndexedArray()
arrayEndsAsExpected()
mustBeNumber()
stripChars()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct()

Class constructor.

Creates an instance

mustBeArray()

mustBeArray(array $input) : array

If the input is not an array, returns an empty array. Otherwise returns the input array

Parameters

array $input

Input to test

Returns

array

mustBeIndexedArray()

mustBeIndexedArray(array $input) : array

If the array must be indexed, this will move the entire contents of an array without a 0 node into a new 0 node

Parameters

array $input

Input to test

Returns

array

arrayEndsAsExpected()

arrayEndsAsExpected(array $inputArray, array $keys, string $expectedType) : bool

Walks the keys in a multi-dimensional array to verify that all intermediate keys exist and that the array ends with the expected type.

This should help avoid lengthy if( array_key_exists... && is_array... test chains

Parameters

array $inputArray

The array to examine

array $keys

And array of key names to examine from the inputArray

string $expectedType

The type of data expected at the end (string, nonempty_string, numeric or array)

Returns

bool

mustBeNumber()

mustBeNumber(mixed $input) : int

Makes sure the input is numeric. If it is not, will return 0;

Parameters

mixed $input

The array to examine

Returns

int

stripChars()

stripChars(string $input, array $chars) : string

Strips characters from $chars from the input sctring

Parameters

string $input

The input string from which characters will be stripped

array $chars

An array of characters to remove from the string

Returns

string