Adding elements to a list array
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.
Figuring
out how many elements are in an array
Table of Contents
Deleting and
replacing list elements with the splice function
|