Adding elements to a PHP Associative Array

I want to set up a PHP Associative Array

I want to dynamicaly add associative elements such as “Title” => “Value1” etc…

Can someone point me to a simple example or even create one to illustrate the concept for me"?

$a = array('foo' => 'bar'); // when you create
$a['Title'] = 'blah'; // later

What happens if you have a collection of something. Lets say CDs Each with their own Artist and Title.

Once you have created the first two elements in the array, how do you then add the next Artist and Title so they automaticaly add on to the array.

Perhaps using the array_push() command?


$collection = array();

$collection[] = array('title' => 'sdfsdf', 'artist' =>'dsfsdf');
$collection[] = array('title' => 'dsfsdfs', 'artist' =>'dswdf');
$collection[] = array('title' => 'ssdfsf', 'artist' =>'dwer');
$collection[] = array('title' => 'sdsdfsd', 'artist' =>'dewrwedf');

foreach($collection as $cd) {
  echo $cd['title'], ' by ', $cd['artist'], "<br>";
}
// or
for($i=0,$j=count($collection); $i<$j, ++$i) {
  echo $collection[$i]['title'], ' by ', $collection[$i]['artist'], "<br>";
}

I think thats exactly what I needed, Thank You