Oihana PHP

hasIntKeys.php

Table of Contents

Functions

hasIntKeys()  : bool
Indicates if all the keys in an array are integers.

Functions

hasIntKeys()

Indicates if all the keys in an array are integers.

hasIntKeys(array<string|int, mixed> $array) : bool

This function checks if every key in the provided array is an integer. Returns true only if all keys are integers, false otherwise.

Parameters
$array : array<string|int, mixed>

The array to check.

Tags
example
$arr1 = [10 => 'a', 20 => 'b', 30 => 'c'];
var_dump(hasIntKeys($arr1)); // true

$arr2 = ['0' => 'a', 1 => 'b', 2 => 'c'];
var_dump(hasIntKeys($arr2)); // false, because '0' is string key, not int

$arr3 = ['foo' => 'bar', 42 => 'baz'];
var_dump(hasIntKeys($arr3)); // false

$arr4 = [];
var_dump(hasIntKeys($arr4)); // true (no keys, so vacuously true)
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
bool

True if all keys are integers, false otherwise.


        
On this page

Search results