An overview of PHP arrays and their classification and declaration code demo _php Tips

Source: Internet
Author: User
Copy Code code as follows:

<?php
/**
* * An overview of an array
1. The nature of the array: manage and manipulate a set of variables, batch processing
2. Arrays are composite types
3. An array can store data of any length. You can also store any type of data
4. Array can complete other language data structure function (linked list, queue, Stack, collection Class)
**
Two. Classification of arrays
There are multiple units in the array, (units are called elements)
Each element is made up of subscript "keys" and values
When you access an element individually, you are accessing the element by subscript "key"
1. One-dimensional array, two-dimensional array, three-dimensional array ... Multidimensional arrays
(An array of arrays in which there are other arrays in the array)

There are two types of arrays in 2.php
Indexed array: is subscript "key" is an index of sequential integers
Associative array: Subscript is a string as an index
Subscript (integer, string) only these two
*
Three. Array Multiple declaration modes
1 assigning values directly to array elements
If the index subscript is not given, it will be indexed starting from 0.
If you give the index subscript, then the next one will be 1 from the biggest start.
If the preceding subscript appears, if the assignment is to reassign the previous element
D mixed-declaration time indexes and associations do not affect each other (without affecting the declaration of index subscript)
2 using the array () function

A default is an indexed array
B. If you make a subscript for an associative array and an indexed array, use the key => value
C Use "," split between multiple members;
3 using a different function declaration
File ();

*
*
*
*
**/

Echo $arr [5]

Indexed arrays
$user []=1;
$user [9]= "John"
$user [0]=10;
$user [3]= "Nan";
$info =array (
"$user" =array (
$user [0]
Array ("1", "John", Ten, "Nan"),
$user [1]
Array ("2", "Lisi", Ten, "Nan"),
$user [2]
Array ("3", "Wangwu", Ten, "Nan"),
),
"$score" =array (
$user [0]
Array ("1", "John", Ten, "Nan"),
$user [1]
Array ("2", "Lisi", Ten, "Nan"),
$user [2]
Array ("3", "Wangwu", Ten, "Nan"),
),

"$connect" =array (
$user [0]
Array ("1", "John", Ten, "Nan"),
$user [1]
Array ("2", "Lisi", Ten, "Nan"),
$user [2]
Array ("3", "Wangwu", Ten, "Nan"),
),
};

$user [][]=1;
$user [][]=1;
$user [][]=1;
$user [][]=1;
$user [][]=1;

?>

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.