PHP: Create an Array of A Range of Characters (Numbers or Letters) or Multiple Identical Values

To create an array of a series of consecutive numbers or alphabetical letters or even any ASCII characters, you can use PHP function range():

$a = range(0, 100, 2); // $a is an array of even integers from 0 to 100.
$b = range('a', 'z'); // $b now contains all lowercase alphabetic letters from a to z.

To create an array of a series of identical values, use function array_fill():

$dumb = array_fill(-10, 3, 'dumb');

$dumb is as follows:

Array
(
    [-10] => 'dumb'
    [-9] => 'dumb'
    [-8] => 'dumb'
)

Yeah.

1 thought on “PHP: Create an Array of A Range of Characters (Numbers or Letters) or Multiple Identical Values”

  1. Pingback: PHP: Create an Array

Comments are closed.

Scroll to Top