Php learning array declaration _ php entry _ script house

Source: Internet
Author: User
Php learning array declaration implementation code. For more information, see.

Php learning array declaration implementation code. For more information, see.

The Code is as follows:
/*
* 1. array Overview
* 1. The essence of Arrays: managing and operating a group of variables
* 2. array composite type (multiple objects can be stored)
* 3. Data of any length or type can be stored in an array
* 4. Arrays can be used to complete data structures in other languages (linked lists, queues, stacks, and collection classes)
*
*
*
* 2. array Classification
* The array contains multiple units (elements)
* Each element (subscript [Key] and value)
* When accessing a single element, all elements are accessed by subscript (key ).
* 1. One-dimensional array, two-dimensional array, and three-dimensional array... Multi-dimensional array
* (The array contains other arrays)
* 2. PHP has two types of arrays.
* Index array: Index where the subscript is an ordered integer
* Associated array: The subscript is a string as an index.
*
* Only these two subscripts (integers and strings) exist.
*
*
* 3. Multiple array declaration Methods
*
* 1. directly assign a value to an array element
* If the index subscript is not given, the index starts from 0.
* If an index subscript is given, the next index increases by 1 from the maximum.
* If the subscript appears next to it, if it is a value assignment, it is to re-assign the value to the previous element.
* When a hybrid declaration is made, the index and association do not affect each other (the declaration of the index subject is not affected)
*
* 2. Use the array () function declaration
* The default value is an index array.
* If you specify a subscript for the associated array and index array, use the key => Value
* Use "," to separate multiple members
* 3. Use other function declarations
*
*
*
*
*/
// Index the Array
$ User [0] = 1; // user serial number
$ User [1] = "zhangsan"; // user Name
$ User [2] = 10; // age
$ User [3] = "nan"; // gender
Echo'
'; 
print_r($user);
echo '
';
// Associate an array
$ User ["id"] = 1;
$ User ["name"] = "zhangsan ";
$ User ["age"] = 10;
$ User ["sex"];
$ User ["age"] = 90; // value assignment
Echo $ user ["name"]; // output
// Use array () to declare an array
$ User = array (1, "zhangsan", 10, "nan ");
// Declare the joined array Using array ()
$ User = array ("id" => 1, "name" => "zhangsan", "age" => 10, "sex" => "nan ");
// Declare multi-dimensional arrays (multiple records) to save multiple user information records in a table
$ User = array (
// Call this line with $ user [0]. For example, call the name in this record, $ user [0] [1]
Array (1, "zhangsan", 10, "nan "),
// Call this line with $ user [1]. For example, call the name in this record, $ user [1] [1]
Array (2, "lisi", 20, "nv ")
);
// Multiple tables are saved in an array. Each table has multiple records.
$ Info = array (
"User" => array (
Array (1, "zhangsan", 10, "nan "),
Array (2, "lisi", 20, "nv ")
),
"Score" => array (
Array ),
Array (2, 60, 40, 70)
)
);
Echo $ info ["score"] [1] [1]; // output 60,
?>

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.