PHP Array - What is an Array?
What is an Array?
An array is a special variable, which can hold more than one value at a time.
For example: if you have a list of items (mobile phone name), storing the mobile phone in single variables could look like this:
$mobile-phone1 = "iPhone";
$mobile-phone2 = "Samsung";
$mobile-phone3 = "Nokia";
$mobile-phone4 = "LG";
However, what if you want to loop through the mobile-phone and find a specific one? And what if you had not 4 mobile-phone, but 250?
Solution is to create an array
An array can hold many values under a single name, and you can access the values by referring to an index number.
Create an Array in PHP - how? - example
In PHP, the array() function is used to create an array.
In PHP language, there are three types of arrays:
Indexed arrays - numeric index,
Associative arrays - named keys,
Multidimensional arrays - containing one or more arrays
$mobile-phone = array("iPhone", "Samsung", "Nokia", "LG");
echo "I like " . $mobile-phone . ", " . $mobile-phone . ", " . $mobile-phone . " and " . $mobile-phone . ".";
PHP cod above will display this result -
PHP Associative Arrays - How to create
PHP Associative Arrays
Associative arrays are arrays that use named keys that you assign to them.
There are two ways to create an associative array:
$mobile-phone = array("Nick"=>"38", "George"=>"39", "Paul"=>"42");
echo "George is ". $age['George'] ." years old.";
PHP Array, what is an rray, arrays
PHP Array - What is an Array? - php tutorial
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
Find here examples of creative and unique website layouts.
Find here examples of creative and unique website CSS HTML menu.