PHP
  Home arrow PHP arrow Page 4 - 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 - Associative Arrays
    (Page 4 of 6 )

    Associative Arrays use an ID key that is not necessarily a numeric value. Here is an example:


    $mystats = array(“Weight”=>900, “Looks”=>1, “IQ”=>12);

    Another way to create an associative array is like this:


    $mystats['Weight'] = 900;

    $mystats['Looks'] = 1;

    $mystats['IQ'] = 12;

    If it still isn't clear, this following coding example should make it so:


    <html>

    <body>

    <?php


    $mystats['Weight'] = 900;

    $mystats['Looks'] = 1;

    $mystats['IQ'] = 12;


    echo “I weigh “ . $mystats['Weight'] . “pounds.”;

    }

    ?>

    The above code would result in the following:

      I weigh 900 pounds.

    As you can see, we call on the index (in this instance "Weight") to retrieve how much I weigh, which prints the value 900. If I had called on "Looks" it would have printed 1, and so forth. So instead of referencing the values in the array with numbers, we just did it with word labels to make it easier to remember and understand (you wouldn't label your files in a file cabinet with numbers, unless you were The Count from Sesame Street that is).

    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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