AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML Tutorial

PHP Array - What is an Array?


<< Previous Page
PHP Loop For Do Foreach
Next Page >>
Convert Array to String



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


Example 1: PHP Indexed Arrays

<?php
$mobile-phone = array("iPhone", "Samsung", "Nokia", "LG");
echo "I like " . $mobile-phone[0] . ", " . $mobile-phone[1] . ", " . $mobile-phone[2] . " and " . $mobile-phone[3] . ".";
?>

PHP cod above will display this result -

css border radius

Note: In an indexed or numeric array, the indexes are automatically assigned and start with 0, and the values can be any data type.

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:

Example 2:
<?php
$mobile-phone = array("Nick"=>"38", "George"=>"39", "Paul"=>"42");
echo "George is ". $age['George'] ." years old.";
?>

The PHP cod above will display this result -

css borderradius

Multidimensional arrays will be explained in the PHP advanced section.

<< Previous Page
PHP Loop For Do Foreach
Next Page >>
Convert Array to String




PHP Array, what is an rray, arrays
PHP Array - What is an Array? - php tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Warning: mysqli_fetch_array() expects pa...
HTML div style property...
CSS bold, Style, Property...
CSS background image size to fit screen ...
PHP convert array to string with commas...
PHP array to comma separated string with...
How to put text in image HTML...
How to insert text in html code using ja...
PHP array_key_exists() Function...
Bootstrap Templates...
Bootstrap Text...
Bootstrap Accordion...
Bootstrap Scrollspy...
Bootstrap Carousel...
Bootstrap Modal...
Bootstrap Responsive Layout...
Bootstrap Fluid Layout...
Bootstrap Fixed Layout...
Bootstrap Grid...
Bootstrap Input...