Definition of arrays in PHP and examples of declarations

Source: Internet
Author: User
Tags array example

The array in PHP is actually an ordered map. A map is a type that associates values to the keys. This type is optimized in many ways, so it can be used as a real array, or as a list (vector), a hash (an implementation of a mapping), a dictionary, a collection, a stack, a queue, and more possibilities. Because the value of an array element can also be another array, the tree structure and the multidimensional array are also allowed.

Role:
1, management and operation of a set of data, data can be any type, arbitrary length.
2, the array is generally composed of keys and values, through the array of subscript to operate.
3, the declaration of the array uses array ().
4. The subscript of the array starts from 0.

Classification:
1. Index array: Subscript is an integer index of the order (starting from 0)
2. Associative array: Subscript is a string index

<?php//Index Array Example $arr1 = Array ("Apple", "orange", "Cup"), $arr 2 = Array ("Ten", "J", "Q", "K", "A");//associative array example $ARR3 = Array ("One "=" "First", "second", "three" and "third"); $arr 4 = Array ("Apple" + "red", "orange" = "Yellow", " Grapes "=" purple ");//fast use of arrays, flexible definition, easy to use.  $arr 5[]=1;  $arr 5[]=3; $arr 5[]=6;?>

Array printing/viewing

<?php//How to view array echo "<pre>" Print_r ($arr 1);//prototype output, view array values and array structure, $arr 1 array variable name, you can change $arr2 or other already declared arrays echo "< ;/pre> "?>


This article from the "Golden Three" blog, declined to reprint!

Definition of arrays in PHP and examples of declarations

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.