PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

WHAT ARE ARRAYS?

Arrays are super complex variables that can store a great amount of values which are indexed and easily referenced.

Arrays make it easier to pass multiple values between pages, code and functions.

PHP arrays are associative - this means that the element values are stored in the array in association with their key values and not in a linear vector format.

Why use arrays?

Arrays make it easier for the PHP programmer to handle large amounts of values. Consider the following:

Assume you want to store the personal details of a person:

Just using variables:

$person_name="John";
$person_email="john@somesite.com";
$person_country="India";

You notice that for each characteristic, we have separate values and separate variables.

If you are using these variables further in your code, passing to another page or passing to functions, you will still have to reference each variable individually which can become messy and confusing.

Now, let's see how easy and simpler it gets with arrays. We can store all of the above three values and variables in one array variable as follows:

$person=array('name' => 'John', 'email' => 'john@somesite.com', 'country' => 'India');

When $person is now used elsewhere in your code, function or passed to a different page, the values can be retrieved as follows:

$person['name'] will be equal to: John
$person['email'] will be equal to: john@somesite.com
$person['country'] will be equal to: India

See also:

How To Create Arrays
How To View Arrays
How To Modify Arrays
Array arsort() Function
Array asort() Function
Array rsort() Function
Array sort() Function
Array ksort() Function
Array krsort() Function
Array Echo
Array list() Function
Manual Array Iteration
Array count() & sizeof() Function




Home | Privacy Policy | Terms Of Use | Contact Us