PHP Tutorials - Herong's Tutorial Examples - v5.18, by Herong Yang
What Is an Array
This section describes what is an array - an ordered pairs of keys and values. If sequential integer keys are used, an array is a simple indexed list. If string keys are used, an array is a map.
What Is an Array? An array is a data type that represents an ordered pairs of keys and values. Arrays in PHP are different than arrays in most of other languages. Basic rules for PHP's arrays are:
1. An array can be constructed by the array constructor, like:
$myArray = array(k1=>v1, k2=>v2, ..., kn=>vn);
where k1, k2, ..., and kn are keys of integer type or string type. v1, v2, ..., and vn are values of any data types.
2. The value of a given key in an array can be expressed by the array variable followed by the key in square brackets, like:
print $myArray[kn];
3. The value of a given key in an array can be modified by an assignment statement, like:
$myArray[kn] = new_value.
4. A new pair of key and value can be added to an array by an assignment statement, like:
$myArray[kx] = vx
5. If a string key represents an integer, it will be used as an integer key. So $myArray['7'] is the same as $myArray[7].
6. If the key is missing in an array assignment or an array constructor, an integer key of 0, or the highest integer key plus 1, will be provided. So $myArray[] = "Last" assigns "Last" to a new integer key.
7. An empty string is also a valid string key, like:
$myArray[''] = vy;
8. A pair of key and value can be removed by using the unset() function, like:
unset($myArray[kn]);
9. Pairs of keys and values are ordered in an array like a queue. New pairs are always added at the end of the array.
Table of Contents
Introduction and Installation of PHP
PHP Data Types and Data Literals
Variables, References, and Constants
Expressions, Operations and Type Conversions
Conditional Statements - "if" and "switch"
Loop Statements - "while", "for", and "do ... while"
Function Declaration, Arguments, and Return Values
Array Related Built-in Functions
Usage Examples of Array Functions
Interface with Operating System
Introduction of Class and Object
Integrating PHP with Apache Web Server
Retrieving Information from HTTP Requests
Creating and Managing Sessions in PHP Scripts
Sending and Receiving Cookies in PHP Scripts
Controlling HTTP Response Header Lines in PHP Scripts
Functions to Manage Directories, Files and Images
Localization Overview of Web Applications
Using Non-ASCII Characters in HTML Documents
Using Non-ASCII Characters as PHP Script String Literals
Receiving Non-ASCII Characters from Input Forms
"mbstring" Extension and Non-ASCII Encoding Management
Managing Non-ASCII Character Strings with MySQL Servers
Configuring and Sending Out Emails
Managing PHP Engine and Modules on macOS