Here is a quck and diry litle tutorial on arrays.
There are single (or standard) arrays, which do not contain association. That means that the keys in an array are numeric with no description at all.
ie:
$a = array('abc','123');
if we look at the structure of the array, it would be equivalent to us saying
or
if you notice, all we are doing is letting php do it's magic by saying "ok, let's build an array like we would an auto-incrementing database table, and place the next available integer as the key and the value whatever the user is requesting"
Now, an associative array is a little different. Again, I'll reference a mysql table here to show the importance and similarities.
Just like in a mysql table, we give descriptive names to fields in a table so that we know what kind of data goes in them.
ie, if we have a table called "users", we would probably have 3 fields: user_id, username, password
An associative array works the same way. Only we don't have to supply the TYPE for the value we are going to store like we would in a mysql table.
In our first example with the array $a, we gave it 2 array values, 'abc' and '123'. But we don't know what type of data that is, or what it's for because we have no descritive words or phrases to explain it. That is where an associative araray comes into play.
we'll recreate it now like so:
Code: Select all
$a = array('letters' => 'abc',
'numbers' => '123');
notice how we defined the array, and told it what to give it as a value.
so now, we could call the values back like so :
Code: Select all
echo $a['letters']; // would echo out abc
echo $a['numbers']; // would echo out 123
we could also define it like this:
Code: Select all
$a['letters'] = 'abc';
$a['numbers'] = '123';
again, we could still call it back the same way.
Both arrays are the exact same. There is no difference at all except that our associative array is a bit more descriptive and easier to read than our normal, standard numeric array.
I hope that doesn't confuse you much and explains it a bit more. Arrays is a very large, extensive learning curve. It's a little hard to grasp at first, but once you start applying it yoursef and trying it out through testing, you'll get it in no time.
A good read is
http://www.php.net/array
Go from there, and google "php array" to get more informatin.