An array, I was taught, is a sequential series of memory locations in which values of some type are stored. In an array, each of the memory locations is the same size (number of bytes). And so,
as I was taught, arrays can be used very efficiently using pointer arithmetic, BUT they need to:
a) Be defined in advance
b) Have each element given enough memory to allow for the biggest content
and
c) They cannot be lengthened later
d) Taking an element out in the middle calls for a lot of shuffling up.
Arrays in PHP and in Tcl are NOT arrays! The word "array" is used more loosely to define a collection object which is (in computer science terms) either a link list or a hash. And that means ...
i) You can define PHP or Tcl arrays as you need them
ii) Elements can have different sizes
iii) Arrays in Tcl of PHP can be expanded as need be
iv) Elements can be deleted easily from the middle
v) Elements can be named (PHP's "associative arrays, all Tcl arrays) rather than numbered
You gain all that flexibility ... what do you loose? For a few applications - the intense dataprocessing / calculation ones - your application may slow down a bit. Since PHP is a web server language where you aren't typically doing such calculations, that turns out to be no loss at all!
(written 2008-04-17 06:40:22)
Associated topics are indexed under
C205 - C and C based languages - Arrays [2840] Just pass a pointer - do not duplicate the data - (2010-06-30)
[2002] New C Examples - pointers, realloc, structs and more - (2009-01-20)
H106 - PHP - Arrays [2920] Sorting - naturally, or into a different order - (2010-08-14)
[2915] Looking up a value by key - associative arrays / Hashes / Dictionaries - (2010-08-11)
[2274] PHP preg functions - examples and comparision - (2009-07-08)
[2215] If nothing, make it nothing. - (2009-06-02)
[1451] More PHP sample and demonstration programs - (2007-12-01)
[1199] Testing for one of a list of values. - (2007-05-22)
[1116] PHP adding arrays / summing arrays - (2007-03-23)
[832] Displaying data at 5 items per line on a web page - (2006-08-14)
[773] Breaking bread - (2006-06-22)
[603] PHP - setting sort order with an associative array - (2006-02-13)
[409] Functions and commands with dangerous names - (2005-08-11)
J705 - Java - Arrays [2648] Java arrays - are they true arrays or not? - (2010-02-23)
[1498] Java is a dynamic language .... (and comparison) - (2008-01-08)
[1497] Training Season Starts again! - (2008-01-07)
T208 - Tcl/Tk - Arrays [2466] Tcl - passing arrays and strings in and back out of procs - (2009-10-22)
[1427] Arrays in Tcl - a demonstration - (2007-11-10)
[1405] Sorting in Tcl - lists and arrays - (2007-10-24)
[1283] Generating traffic for network testing - (2007-07-29)
[1282] Stringing together Tcl scripts - (2007-07-29)
[779] The fragility of pancakes - and better structures - (2006-06-26)
[122] Passing arrays to procs in Tcl - (2004-11-18)
Some other Articles
A small picture does not always cut it!Steam Engines at BressinghamNot daring to be an anorakPHP training courses every monthWhen an array is not an arrayRegular expression for 6 digits OR 25 digitsComfy Chair - Floating Harbour, BristolGauging point at entrance to Bristols Floating HarbourPHP course dot co, dot ukChew Valley Lakes