Mining PHP Array function library array array create and use _php tutorial

Source: Internet
Author: User
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

 
 
  1. php
  2. $ Fruits = Array (
  3. "Fruits" = > Array ("a" => "Orange", "b" => "Banana", "c"=> "Apple"),
  4. "Numbers" = > Array (1, 2, 3, 4, 5, 6),
  5. "holes" = > Array ("First", 5 => "Second", "third")
  6. );
  7. ?>

PHP Array Function library Example 2. Automatic indexing of Array ()

 
  
  
  1. Php
  2. $ Array Array = Array (1, 1, 1, 1, 8 => 1, 4 = >3 => );
  3. Print_r ($array);
  4. ?>

The example above will output:

 
  
  
  1. Array
  2. (
  3. [0] => 1
  4. [1] => 1
  5. [2] => 1
  6. [3] =>
  7. [4] => 1
  8. [8] => 1
  9. [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 ...

  • 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.