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, updated 2008-04-19)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
T208 - Tcl/Tk - Arrays and dicts [122] Passing arrays to procs in Tcl - (2004-11-18)
[779] The fragility of pancakes - and better structures - (2006-06-26)
[1282] Stringing together Tcl scripts - (2007-07-29)
[1283] Generating traffic for network testing - (2007-07-29)
[1405] Sorting in Tcl - lists and arrays - (2007-10-24)
[1427] Arrays in Tcl - a demonstration - (2007-11-10)
[2466] Tcl - passing arrays and strings in and back out of procs - (2009-10-22)
[3192] Tcl - Some example of HOW TO in handling data files and formats - (2011-03-04)
[3415] User defined sorting and other uses of callbacks in Tcl and Tk - (2011-09-02)
[3582] Tcl collections - lists, dicts and array - (2012-01-16)
[3614] Tcl - dicts - a tutorial and examples - (2012-02-14)
[3638] Sorting dicts and arrays in Tcl - (2012-03-04)
J705 - Java - Arrays [1497] Training Season Starts again! - (2008-01-07)
[1498] Java is a dynamic language .... (and comparison) - (2008-01-08)
[2648] Java arrays - are they true arrays or not? - (2010-02-23)
[3038] Setting up individual variables, and arrays, in Java - some commented examples - (2010-11-09)
[3039] Fresh Paint - Java Arrays - (2010-11-09)
[3118] Arrays of arrays - or 2D arrays. How to program tables. - (2011-01-02)
[4347] Arrays in Java - an introduction for newcomers - (2014-12-10)
[4413] Binomial Coefficient (Pascal Triangle) objects in Java - (2015-02-03)
[4428] Using the lead - passing arrays and other collections in Java - (2015-02-16)
H106 - PHP - Arrays [409] Functions and commands with dangerous names - (2005-08-11)
[603] PHP - setting sort order with an associative array - (2006-02-13)
[773] Breaking bread - (2006-06-22)
[832] Displaying data at 5 items per line on a web page - (2006-08-14)
[1116] PHP adding arrays / summing arrays - (2007-03-23)
[1199] Testing for one of a list of values. - (2007-05-22)
[1451] More PHP sample and demonstration programs - (2007-12-01)
[2215] If nothing, make it nothing. - (2009-06-02)
[2274] PHP preg functions - examples and comparision - (2009-07-08)
[2915] Looking up a value by key - associative arrays / Hashes / Dictionaries - (2010-08-11)
[2920] Sorting - naturally, or into a different order - (2010-08-14)
[3004] Increment operators for counting - Perl, PHP, C and others - (2010-10-18)
[3379] Sorting data the way YOU want it sorted - (2011-08-05)
[3534] Learning to program in PHP - Regular Expression and Associative Array examples - (2011-12-01)
[4068] Arrays in PHP - contain different and even mixed data types - (2013-04-24)
[4072] Splitting the difference with PHP - (2013-04-27)
[4244] Disambiguation - PHP List - (2014-03-07)
C205 - C and C based languages - Arrays [2002] New C Examples - pointers, realloc, structs and more - (2009-01-20)
[2840] Just pass a pointer - do not duplicate the data - (2010-06-30)
[3121] New year, new C Course - (2011-01-05)
[3144] Setting up arrays in C - fixed size at compile time, or dynamic - (2011-01-24)
[3245] Collections in C and C++ - arrays, vectors and heap memory blocks - (2011-04-12)
[4338] Passing arrays into functions in C - (2014-12-02)
[4566] C - why is slow to write and debug) but fast to run? - (2015-11-01)
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