Arrays

PHP arrays are easy to use, provide great flexibility, and have few traps. You can use PHP arrays like mini databases in memory, as there is a rich range of functions for sorting and processing arrays. Data stored in text files, print files, XML files, and databases can be loaded into an array and then processed without disrupting the original file.

This chapter on Arrays contains the following sections:
   In Depth
      Simple Arrays
         The World's Simplest Array
         Array Are Numbered from Zero
         Array Elements can Be Named Anything
         Array Creation Functions
      Potential Problems
      Multiple Dimensions
      The Array Pointer
      Sorting Arrays
      Push, Pop, Pad, and Merge
         Push and Pop
         Pad
         Merge
   Immediate Solutions
      Creating Arrays from Lists with array()
      Creating Arrays from Strings with explode()
      Creating Strings from Arrays with implode()
         Basic SQL
         select
            bold
         where
            bold
         order by
            bold
         group by
            bold
         Building the SQL
      Specifying a Range of Elements with range()
      Specifying a Key Range with range() and array_flip()
      Removing Duplicate Array values with array_flip()
      Randomizing an Array with shuffle()
      Randomizing Banners with array_rand()
      Reading a File into an Array with file()
      Sorting an Array by Value with sort()
      Sorting an Associative Array by Value with asort()
      Sorting an Array by Value in Reverse Order with rsort()
      Sorting an Associative Array in Reverse order with arsort()
      Sorting an Associative Array by Key with ksort()
      Sorting an Array by Value Naturally with natsort()
      Sorting an Array unnaturally with usort()
      Looping through an Array Backward
      Looping through Multidimentional Arrays