toIntegers.php
Table of Contents
Functions
- toIntegers() : array<int, int>
- Filters a value down to a list of integers, keeping every integer and every string that writes one, and dropping the rest.
Functions
toIntegers()
Filters a value down to a list of integers, keeping every integer and every string that writes one, and dropping the rest.
toIntegers(mixed $value) : array<int, int>
The value is first passed through toArray() (a bare scalar is wrapped as a
single-element list), then walked : an int is kept as is ; a string is kept,
cast to int, when it writes an integer and nothing else — an optional sign, digits,
surrounding spaces allowed, leading zeros included ('007' gives 7). Anything else
is dropped : a float — even 350.0 —, a string holding a decimal, an exponent or a
hexadecimal number, a bool, null, an array, an object.
Unlike toInt(), which converts one value and falls back
to 0, this filters a list : what is not an integer has no place in it, and a
decimal is never truncated into one.
Parameters
- $value : mixed
-
The value to filter — an array, or a bare scalar wrapped via
toArray().
Tags
Return values
array<int, int> —The kept items, as integers, in their order, duplicates included, re-indexed from 0.