PHP
  Home arrow PHP arrow Page 2 - PHP: The Switch Statement and Arrays
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 5
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT