The function library in the array is the main point of our learning array, we mainly introduce the PHP Array function library array to create an array, and everyone to share it. Fortunately, PHP is not difficult, these things are not many, and then learn a few lessons we can start to use it to achieve a website function, then I believe you will become more and more energetic. Well, start today's course. Today we learn arrays, arrays are a type of data, it is used fairly high frequency, learn to deal with the array will let you do the site handy.
For example: Your site database has a Dali article, now you want to display 20 entertainment news on a page title, the 20 headings from the database after you want to use 20 variables to represent it? I think you are not so stupid, so what variables can fully receive the 20 data? This will use the array variable. What is an array? Array is actually a data collection, equivalent to a data container, a lot of data stored in the inside, we can be stored in or out of a certain way, but also the data inside it can be sorted and other operations, but also to check if there is no data we want, and so on.
PHP Array function library new array using array
Returns an array created from a parameter. Parameters can be indexed with the-= operator. For information on what an array is, read the array section. Note: Array () is a language structure that is used to literally represent an array, not a regular function. The syntax "index = values", separated by commas, defines the index and value. The index can be a string or a number. If the index is omitted, an integer index starting from 0 is automatically generated. If the index is an integer, the next resulting index will be the current largest integer index + 1. Note If you define two identical indexes, the next one overwrites the previous one. Adding a comma after the last defined array item is not common, but it is a valid syntax.
The following example shows how to create a two-dimensional array, how to assign a key name to the corresponding array, and how to skip and continue the numeric index in a normal array.
PHP Array Function library Example 1. Array () example
- php
- $ Fruits = Array (
- "Fruits" = > Array ("a" => "Orange", "b" => "Banana", "c"=> "Apple"),
- "Numbers" = > Array (1, 2, 3, 4, 5, 6),
- "holes" = > Array ("First", 5 => "Second", "third")
- );
- ?>
PHP Array Function library Example 2. Automatic indexing of Array ()
- Php
- $ Array Array = Array (1, 1, 1, 1, 8 => 1, 4 = >3 => );
- Print_r ($array);
- ?>
The example above will output:
- Array
- (
- [0] => 1
- [1] => 1
- [2] => 1
- [3] =>
- [4] => 1
- [8] => 1
- [9] =>
Note that index 3 is defined two times and retains the last value of 13. Index 4 is defined after index 8, and the next auto-generated index (with a value of 19) is 9 because the largest index is 8.
http://www.bkjia.com/PHPjc/446543.html www.bkjia.com true http://www.bkjia.com/PHPjc/446543.html techarticle The function library in the array is the main point of our learning array, we mainly introduce the PHP Array function library array to create an array, and everyone to share it. Fortunately PHP is not difficult, these East ...