Home > Articles > Programming > PHP

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book


PHP gives you some great ways of working with data in strings and arrays. Both have many different functions available. Here's a summary of the salient points in this chapter:

  • The many string functions do everything from searching strings to formatting them for display. Take a look at Table 3-1 for a refresher.
  • The printf and sprintf functions format strings for display.
  • The strstr function searches a string for a substring.
  • The substr_compare function lets you compare strings.
  • You access the items in an array by using a numeric or string index.
  • PHP knows you're working with an array if you include [] after a variable's name.
  • The unset function removes items from arrays.
  • The foreach statement provides a great way of looping over arrays.
  • The array functions do everything from merging arrays to searching them.
  • You can sort arrays with the sort function.
  • You can convert between strings and arrays using the PHP implode and explode functions.
  • You can use the array_diff function to create a new array that holds the elements that are different between two arrays.
  • You can create multidimensional arrays simply by using two array indexes in square brackets, [ and ].

That's it for our coverage of strings and arrays for the moment, both of which we'll see again throughout the book. Now it's time to turn to working with and creating functions in Chapter 4, "Breaking It Up: Functions."

  • + Share This
  • 🔖 Save To Your Account