Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Create an Array with a Sequence of Integers or Characters
How To Create an Array with a Sequence of Integers or Characters? - PHP Script Tips - PHP Built-in Functions for Arrays
✍: FYIcenter.com
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
(
[0] => 1
[1] => 4
[2] => 7
[3] => 10
[4] => 13
[5] => 16
[6] => 19
)
Characters:
Array
(
[0] => X
[1] => Y
[2] => Z
[3] => [
[4] => \
[5] => ]
[6] => ^
[7] => _
[8] => `
[9] => a
[10] => b
[11] => 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.
2007-04-21, 5504👍, 0💬
Popular Posts:
What will be printed as the result of the operation below: main() { int a=0; if (a==0) printf("Cisco...
What are the different accessibility levels defined in .NET ? Following are the five levels of acces...
I have 5 questions please give me the answer ,explanation,suggestions if any?? what is PMP(project m...
How do you locate the first X in a string txt? A) txt.find('X'); B) txt.locate('X'); C) txt.indexOf(...
How To Define a Data Source Name (DSN) in ODBC Manager? - Oracle DBA FAQ - ODBC Drivers, DSN Configu...