introduction to web programming Adding elements to a list array Likewise, you can add to or modify the values of an existing array by simply referencing the array by number. For example, to add an element to @available_colors, you might use the following line:

     $available_colors[4] = "orange";

Thus, @available_colors would include the elements: red, green, blue, brown, and orange.

You can also use this method to overwrite an element in a list array. To change a value in @available_colors, you might use the syntax:

     $available_colors[0] = "yellow";

Now, the elements of @available_colors would be: yellow, green, blue, brown, orange.

Previous | Next | Table of Contents