Creating an Array with a Sequence in PHP
How To Create an Array with a Sequence of Integers or Characters in PHP?
The quickest way to create an array with a sequence of integers or characters is to use the range() function. It returns an array with values starting with the first integer or character, and ending with the second integer or character. Here is a PHP script on how to use range():
<?php print("Integers:\n"); $integers = range(1, 20, 3); print_r($integers); print("\n"); print("Characters:\n"); $characters = range("X", "c"); print_r($characters); print("\n"); ?>
This script will print:
Integers: Array (  => 1  => 4  => 7  => 10  => 13  => 16  => 19 ) Characters: Array (  => X  => Y  => Z  => [  => \  => ]  => ^  => _  => `  => a  => b  => c )
Of course, you can create an array with a sequence of integers or characters using a loop. But range() is much easier and quicker to use.
2017-01-05, 1666👍, 0💬
How to search for the first match of a regular expression using re.search()? The re.search() functio...
FYIcenter.com Online Tools: FYIcenter JSON Validator and Formatter FYIcenter JSON to XML Converter F...
How to detect errors occurred in the json_decode() call? You can use the following two functions to ...
Where to find tutorials on Visual Studio? I want to know How to learn Visual Studio. Here is a large...
How to use the "set-body" Policy Statement for an Azure API service operation? The "set-body" Policy...