Common array manipulation functions in PHP (1/8) _php Tutorial

Source: Internet
Author: User
An array is a set of elements that have some common characteristics, including similarity and type.
Each element is distinguished by a special identifier, called key, and each key has a value
1. Two ways to create an array:
1.1 using the array () function

The code is as follows Copy Code

$usernames = Array (' Alerk ', ' Mary ', ' Lucy ', ' Bob ', ' Jack ', ' John ', ' Mark ');
foreach ($usernames as $name)
{
Echo $name. '
';
}
?>

Output
Alerk
Mary
Lucy
Bob
Jack
John
Mark

1.2 Using the range () function

The code is as follows Copy Code

$numbers = Range (0, 10);
foreach ($numbers as $num)
{
Echo $num. '
';
}
$letters = Range (' A ', ' Z ');
foreach ($letters as $letter)
{
Echo $letter. '
';
}
?>

Output
0
1
2
3
4
5
6
7
8
9
10
A

C
D
E
F
G
H
I
J
K
L
M

O

Q
R

T
U
V
W
X
Y
Z

2. Iterate through the array elements in two ways:
2.1 For Loop

The code is as follows Copy Code

The third parameter of range indicates the step size
$numbers = range (1,10,2);
for ($i = 0; $i
{
echo $numbers [$i]. '
';
}
?>

Output
1
3
5
7
9

1 2 3 4 5 6 7 8

http://www.bkjia.com/PHPjc/629237.html www.bkjia.com true http://www.bkjia.com/PHPjc/629237.html techarticle An array is a set of elements that have some common characteristics, including similarity and type. Each element is distinguished by a special identifier, called key, and each key has a value of 1. Create number ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.