Working With Arrays in PHP

Arrays are common to many programming languages. They are special variables which can hold more than one value, each stored in its own numbered 'space' in the array. Instead of having many similar variables, you can store the data as elements in an array.Each element in the array has its own ID so that it can be easily accessed.

There are three different kind of arrays:

Numeric array - An array with a numeric ID key

Associative array - An array where each ID key is associated with a value

Multidimensional array - An array containing one or more arrays

Numeric Arrays

A numeric array stores each element with a numeric ID key. There are different ways to create a numeric array.

Associative Arrays

An associative array, each ID key is associated with a value.When storing data about specific named values, a numerical array is not always the best way to do it.With associative arrays we can use the values as keys and assign values to them.

Example 1

In this example we use an array to assign ages to the different persons:

$ages = array("John"=>32, "Paul"=>30, "Steve"=>34);

Example 2

This example is the same as example 1, but shows a different way of creating the array:

<?php
function arrays($array1,$array2)
{
echo $array1.' '.$array2;
}
arrays(myname,lastname);
echo arays();
?>
Is this code is correct and where is the fault and how i can change it . i want that user enter value in it and it show its name and last name in an array in the database.

If u want that the user should enter the values and it should be displayed on the database. Then you have to accept the values from the form and use the command : mysql_query("INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)"); to insert into the database