Categories
PHP Tips & Tutorials

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.

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.

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

Comments are closed.