Arrays in PHP

I got most of the information from the site PHP Arrays. I also found the information from the book on this general topic to be most insightful. Previous to doing this weeks assignment I knew what arrays were and there basic implementation from working in class and working with other programming languages.

Arrays

In php an array is an object that is used to store other objects. Most of the time the objects that are being stored have something in common or will be used in the same ways. I found it interesting that in PHP ther are three different types of arrays.

  • Numeric: Uses a numeric key.
    Example: $names[0] = "Peter"; $names[1] = "Quagmire"; $names[2] = "Joe";
  • Associative: Uses a ID key associated with the value.
    Example: $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34";
  • Multidimensional: This is an array of one or more arrays.
    Example: $families = array("Griffin"=>array("Peter"), "Quagmire"=>array("Glenn"),"Brown"=>array("Cleveland"));

Arrays can be very easy to use. One nice thing about arrays in PHP is that they are automatically dynamic. This means that they will grow and shrink as needed. Arrays are a nice way to store and retrieve data easily.

Working Example / References

This is a hard one to show a working example of on the web. As far as references I did find that there are many out there. One really good one that goes really in depth is the PHP Arrays Manual. This site not only shows how to work with the arrays but it also show how to manipulate them using built in fuctions.