Page 166 - Beginning PHP 5.3
P. 166

Part II: Learning the Language






































                  Figure 6-7


                       array_multisort()  preserves associations between string keys and their values, but it reindexes
                    numeric keys.


                  Adding and Removing Array Elements

                   You already know that you can add elements to an array using square bracket syntax. For example:
                    $myArray[] = “new value”;
                    $myArray[“newKey”] = “new value”;

                   This syntax is fine for simple scenarios. However, if you need something more powerful, PHP features
                 five useful functions that you can use to add and remove elements:
                   ❑       array_unshift()  – – Adds one or more new elements to the start of an array



                   ❑       array_shift()  – –  Removes the first element from the start of an array


                   ❑       array_push()  —  Adds one or more new elements to the end of an array


              128





                                                                                                      9/21/09   9:00:19 AM
          c06.indd   128                                                                              9/21/09   9:00:19 AM
          c06.indd   128
   161   162   163   164   165   166   167   168   169   170   171