O'Reilly logo

PHP for Teens by Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with Arrays

The following functions let you use arrays in various ways throughout your program.

unset() Function

When you are done working with array values, sometimes it is nice to get rid of them altogether. You might need to use them again later in the program, and want to reuse the keys without worrying about overwriting data. PHP offers the unset() function to get rid of old array values (or, for that matter, old arrays). The function unset() works by only unsetting exactly the parameter you pass to it. Unsetting an array is useful for memory management.

If you want to create an array with five values, you could write something like the following, which ends up looking like Figure 10.5:

Figure 10.5. Before using unset().

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required