webCOMAND

array_util::is_associative()

Check to see if the array is associative (i.e. non-consecutive keys that are numbers or strings).

Prototype

is_associative(array $array) : bool

Parameters

  • array - Array to check.

Return

Return TRUE if the array contains non-consecutive keys that are numbers or strings.  Otherwise FALSE.

Example

use \io_comand_util\array_util;

$array1 = [
    'people' => ['Mary', 'Bill'],
    'places' => ['Canada', 'United States']
];
$array2 = [5, 2, 'hello', 4];
// will be TRUE (1)
echo('Array 1: ' . array_util::is_associative($array1));
// will be FALSE ()
echo('Array 2: ' . array_util::is_associative($array2));