PHP
  Home arrow PHP arrow Page 2 - PHP: The Switch Statement and Arrays
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP: The Switch Statement and Arrays
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2008-01-07

    Table of Contents:
  • PHP: The Switch Statement and Arrays
  • The Variable's Big Brother
  • Printing the Array Values
  • Associative Arrays
  • The Multidimensional Array
  • Beyond Multidimensional Arrays

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    PHP: The Switch Statement and Arrays - The Variable's Big Brother
    (Page 2 of 6 )

    Yeah you heard me. You'd better not mess with the variable, or he'll get his big brother, the Array, to lay the goon hand down on you. And you don't want that, because he is bigger, badder, and holds a lot more data.

    Arrays in PHP are similar to the arrays in most programming languages. Like a variable, they hold data. Unlike variables, they hold more than one piece of data. They can hold as many as you like, what with their giant, rippling muscles. There are three types of arrays, and we are going to discuss them all here. They are the Numeric Array, the Associative Array, and my favorite, the squeezably soft Multidimensional Array.

    Numeric Arrays

    The name of the Numeric Array is a little misleading. When I first read it I thought they only stored numbers, which of course is wrong. The Numeric part simply refers to how the values in an array are stored. Other languages were smart enough not to name their arrays Numeric; I don't know why PHP wasn't.

    The easiest way to think of an array is like a drawer with many file folders in it. Each file within the drawer holds data. If that is confusing, then gaze at my marvelous code, which will enlighten your puny brain:


    $mygirlfriends = array(“Your Mother”, “Angelina Jolie”, “Whitney White”);

    In the above example, PHP automatically assigns the numeric index to your array. The value in the first position (Your Mother) gets the index of 0, the second position (Angelina Jolie) gets 1, and the third position (Whitney White) gets the index 2.

    If we wanted to assign the index number manually, we could also write it this way:


    $mygirlfriends[0] = “Your Mother”;

    $mygirlfriends[1] = “Angelina Jolie”;

    $mygirlfriends[2] = “Whitney White”;

    Both ways store the information the same way; which is the best manner to assign the array values is up to you.

    More PHP Articles
    More By James Payne


       · There is a mistake in codeinstead of $mygirlfriends[1] . “and” . $names[2]...
       · Hey thanks for catching that. They tie me up in a dungeon and force me to write...
     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway