PHP learning notes-array (1), php learning notes Array

Source: Internet
Author: User
Tags array definition

PHP learning notes-array (1), php learning notes Array

1-1 array Definition

1. What is an array?

An array is a set of elements of the same data type arranged in a certain order. It is to name a variable of the same type with a name, and then identify the set of their variables with a number, this name is called the array name and the number is called the subscript. Each variable that makes up an array is called the component of an array, also known as an element of an array, or a subscript variable.

Syntax:

<? Php // set a variable to an empty array $ arr = array ();?>

1-2 Index Array Initialization

PHP has two types of Arrays: Index Array and associated array.

Both indexes and associations are for the keys of arrays.

An index array is an array of keys and integers in an index group. The order of keys starts from 0, and so on.

<? Php $ num = array (1, 2, 3); print_r ($ num [0]);?>

Output result: 1

1-3 index array assignment

Three methods

<? Php $ arr [0] = 1; // method 1 $ arr = array ('0' => 1); // method 2 $ arr = array (1 ); // method 3?>

1-4 access the array content

<? Php // from the array variable $ arr, the read key is 0 value $ arr = array (, 3); $ arr0 = $ arr [0]; echo $ arr0;?>

 

 

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.