PHP arrays can be numerically indexed or associative, and can contain multiple dimensions. They can be constructed and accessed in various ways, and useful functions include print_r, count, sort, and explode. Superglobals provide access to GET, POST, COOKIE, and SESSION variables.
PHP arrays can be numerically indexed or associative, and can contain multiple dimensions. They can be constructed and accessed in various ways, and useful functions include print_r, count, sort, and explode. Superglobals provide access to GET, POST, COOKIE, and SESSION variables.
In PHP an array is an ordered map that associates keys with
values PHP has two types of arrays Numerically indexed arrays use integers as keys Associative arrays typically use strings as keys Constructing Arrays with Integer Keys
Associative arrays map keys other than integers to values
<?php $b['one'] = 1; $b['two'] = 2; $b['three'] = 3; ?> If multiple elements are declared with the same key, then only the value of the last element is used Key Casts
A string containing an integer will be cast to an integer
A float is cast to an integer A bool is cast to an integer The null value will be cast to an empty string Arrays and objects cannot be used as keys Printing Arrays
The print_r function prints a human readable representation
of an array An element of an array can be used as a variable for string interpolation purposes echo "$a[0]"; If the key is not an integer then the array element must be surrounded by curly braces for string interpolation echo "${b['one']}"; The array keyword
count returns the number of elements in an array sort performs an in-place sort of an array explode converts a string into an array Superglobals
Superglobals are predefined variables that are provided by the
PHP environment $_GET: variables passed to the current script via the HTTP GET method $_POST: variables passed to the current script via the HTTP POST method $_COOKIE: variables passed to the current script via HTTP cookies $_SESSION: session variables available to the current script