|
PHP Arrays
|
|
05-19-2009, 07:07 PM
Post: #1
|
|||
|
|||
|
PHP Arrays
PHP Arrays
An array can store one or more values in a single variable name. What is an array? When working with PHP, sooner or later, you might want to create many similar variables. 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. Example 1 In this example the ID key is automatically assigned: PHP Code: $names = array("Peter","Quagmire","Joe"); PHP Code: In this example we assign the ID key manually:The ID keys can be used in a script: PHP Code: <?phpThe code above will output: Quagmire and Joe are Peter's neighbors 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: PHP Code: $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); Example 2 This example is the same as example 1, but shows a different way of creating the array: PHP Code: $ages['Peter'] = "32";The ID keys can be used in a script: PHP Code: <?phpThe code above will output: Peter is 32 years old. Multidimensional Arrays In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. Example In this example we create a multidimensional array, with automatically assigned ID keys: PHP Code: $families = arrayThe array above would look like this if written to the output: PHP Code: ArrayExample 2 Lets try displaying a single value from the array above: PHP Code: echo "Is " . $families['Griffin'][2] . The code above will output: Is Megan a part of the Griffin family? My Main Site My Forum |
|||
|
07-15-2010, 11:15 PM
Post: #2
|
|||
|
|||
|
RE: PHP Arrays
PHP array is actually signed the map. The map is a type that maps key values. This type is optimized for several different uses, which can be regarded as an array, list (vector), seal (in implementation of the map), dictionary, collection, stack, queue and probably more. Since the matrix values can be s array of other, trees and multidimensional arrays t are also possible.
shopping vouchers |
|||
|
09-07-2010, 09:01 PM
Post: #3
|
|||
|
|||
|
RE: PHP Arrays
It is great thing .. All are awe about it. But Nice to share although information. I hope that We will discuss more important aspects of the PHP arrays
seo services india |
|||
|
« Next Oldest | Next Newest »
|

Search
Member List
Calendar
Help



