The Photoshop Learning Forum PHP Learning Array Declaration

Source: Internet
Author: User
Copy CodeThe code is as follows:


/*
* First, an overview of arrays
* 1. The nature of the array: managing and manipulating a set of variables, batch processing
* 2. Compound type when array (multiple can be stored)
* 3. You can store any length of data in an array, or you can store any type of data
* 4. Array can complete the function of other language data structure (list, queue, Stack, collection Class)
*
*
*
* Second, the classification of the array
* There are multiple cells in the array (cells are called elements)
* each element (subscript [key] and value)
* When a single element is accessed, the element is accessed by subscript (key)
* 1. One-dimensional arrays, two-dimensional arrays, three-dimensional arrays ... Multidimensional arrays
* (Array of arrays, which is the existence of other arrays in the array)
* There are two types of arrays in 2.PHP
* Index array: is the index of an ordinal integer that is the subscript
* Associative array: Is the subscript is the string as the index
*
* Subscript (integer, string) only these two types of
*
*
* Three, array of multiple declaration methods
*
* 1. Direct array element Assignment declaration
* If index subscript is not given, it will be indexed sequentially from 0
* If index subscript is given, the next will increase by 1 from the largest start
* If the previous subscript appears, the assignment is to reassign the previous element
* When mixing declarations, indexes and associations do not affect each other (do not affect the declaration of index subscript)
*
* 2. Using the array () function declaration
* Default is indexed array
* If you specify subscripts for associative arrays and indexed arrays, use the key = = value
* use "," split between multiple members
* 3. Use a different function declaration
*
*
*
*
*/
Indexed array
$user [0]=1;//User number
$user [1]= "Zhangsan";//username
$user [2]=10;//Age
$user [3]= "Nan";//gender
Echo '



Echo '
';
Associative arrays
$user ["id"]=1;
$user ["Name"]= "Zhangsan";
$user ["Age"]=10;
$user ["Sex"];
$user ["Age"]=90;//assignment
echo $user ["name"];//output
Declaring an array using array ()
$user =array (1, "Zhangsan", Ten, "Nan");
Declaring an associative array using array ()
$user =array ("id" =>1, "name" = "Zhangsan", "Age" =>10, "sex" = "Nan");
declaring multidimensional Arrays (multiple records) to hold multiple user information records in a table
$user =array (
Call this line with $user[0], such as calling the name in the record, $user [0][1]
Array (1, "Zhangsan", Ten, "Nan"),
Call this line with $user[1], such as calling the name in the record, $user [1][1]
Array (2, "Lisi", "NV")
);
Arrays save multiple tables with multiple records per table
$info =array (
"User" =>array (
Array (1, "Zhangsan", Ten, "Nan"),
Array (2, "Lisi", "NV")
),
"Score" =>array (
Array (1,90,80,70),
Array (2,60,40,70)
)
);
echo $info ["score"][1][1];//output 60,
?>

The above describes the Photoshop Learning Forum PHP Learning array declaration, including the Photoshop Learning forum content, I hope to be interested in PHP tutorial friends helpful.

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