Commonly used array operation functions in php (1/8)

Source: Internet
Author: User

An array is a group of elements with some common characteristics, including similarity and type.
Each element is distinguished by a special identifier, called a key, and each key has a value
1. Two ways to create an array:
1.1 Use the array () function

The code is as follows: Copy code

<? Php
$ Usernames = array ('aler', 'Mary ', 'Lucy', 'Bob', 'Jack', 'John', 'mark ');
Foreach ($ usernames as $ name)
{
Echo $ name. '<br/> ';
}
?>

Output
Alerk
Mary
Lucy
Bob
Jack
John
Mark

1.2 Use the range () function

The code is as follows: Copy code

<? Php
$ Numbers = range (0, 10 );
Foreach ($ numbers as $ num)
{
Echo $ num. '<br/> ';
}
$ Letters = range ('A', 'z ');
Foreach ($ letters as $ letter)
{
Echo $ letter. '<br/> ';
}
?>

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. Two methods to access array elements cyclically:
2.1 for loop

The code is as follows: Copy code

<? Php
// The third parameter of range indicates the step size.
$ Numbers = range (1, 10, 2 );
For ($ I = 0; $ I <count ($ numbers); $ I ++)
{
Echo $ numbers [$ I]. '<br/> ';
}
?>

Output
1
3
5
7
9

Home 1 2 3 4 5 6 7 8 Last page
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.