TOP TECH
  Learn How to.....
Welcome IT Related Articles Member Area  |  Sign In  |  Sign Up
.: Home :.
General
HTML
CSS
PHP
PHP-MySQL
FrontPage
Photoshop
CorelDRAW
PageMaker
MS Office
VisualBasic
All
.

.: Home :.

Home >> PHP - MySQL
Programming with PHP 2.2 [Page 1]
Article by: Shelton Manage
Wednesday, 03rd June, 2009


What are Arrays?

Arrays are very powerful and useful tool for PHP programmers. So much so that PHP users several types of arrays by default, an array can hold multiple, seperate pieses of information. An array is therefor like list of values, each vlue being a string or a numbers or even anothor array.

PHP supports two kind of arrays: indexed and associative. An array can even use a combination numbers and strings as its keys. The only important rule is that the keys of an arrary must be unique.

Array Example 1:$actors

Key - Value
0 - Amithab Bhachchan
1 - Sharuk Khan
2 - Hithik Roshan
3 - Ameer Khan

Array Example 2:$states

BM - Bombay
MB - Mumbai
CP - Charanpoor
KT - Kolcata

To retrieve a specific value from an array, you refer to the arrary name first, followed by the key, in square brackets:

echo $actors[2] // Hithik Roshan
echo $staes[BM] // Bombay

Becauae arrays use a differant syntax than other variables, printing them in trickier. for example, the following code will case a parse error: echo "BM is the abbreviation for $states['BM']."; the aroud this, wrap your array name and key in curly braces: echo "BM is the abbreviation for {$states['BM']}."

It's not requreed in PHP to enclose your keyes with quotation marks when reffering to array elements ($array[key]).



Page: First - 1 2 3 4 5 6 - Last

 



Comments


© 2009 Top Sri Lanka Top Tech.
Articles Manager β - Script by: DynamicCodes.com