Commonly used array operation functions in php (18 ). 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 value1. creating a number 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: |
|
$ Usernames = array ('aler', 'Mary ', 'Lucy', 'Bob', 'Jack', 'John', 'mark '); Foreach ($ usernames as $ name) { Echo $ name .' '; } ?> Output Alerk Mary Lucy Bob Jack John Mark |
1.2 Use the range () function
| The code is as follows: |
|
$ 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. two methods to access array elements cyclically:
2.1 for loop
| The code is as follows: |
|
// 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
Bytes. Each element is distinguished by a special identifier, which is called a key, and each key has a value 1. creation number...