PHP arrays

PHP arrays

PHP arrays introduction

Arrays are used for storing one or more values in a single variable name. Each element of an array has its own ID for easy access. Arrays can be of the following types:

Numeric: An array with numeric ID key

Example:
$names = array(“Mike”, “Perry”);

Above array can be interpreted as :- array[0]= mike and array[1]= perry

Associative: An array in which each ID key is associated with a value.

Example:
$ages = array("mike"=>32, "perry"=>30);

Multidimensional: Having more than one array

Example:
$families = array
(
    "lawson"=<array
(
    "Peter",
    "Lois",
    "Megan"
),
    "james"=<array
(
    "Glenn"
)
);

Explain the purpose of $GLOBALS superglobal array with an example.

$GLOBAL array contains all the global variables used in the script. The variable names are the keys of the array.
PHP operator
Operators are generally used to operate on values. Following are the types of operator’s used in PHP.
PHP class
PHP classes help to deal with data in an organized fashion.
PHP inheritance
Inheritance is a mechanism that extends and existing class.
Post your comment