Home arrow PHP arrow Page 6 - PHP: The Switch Statement and Arrays

Beyond Multidimensional Arrays - PHP

In our last exciting adventure (back in early November), we braved crocodiles, ravenous editors, most of the PHP statements, and beginning loops. In this edition we'll cover the final statement, the Switch, and discuss arrays. So sit back, order your R2D2 robot to bring you a cold, frosty Jolt Cola, and let's get cracking.

TABLE OF CONTENTS:
  1. PHP: The Switch Statement and Arrays
  2. The Variable's Big Brother
  3. Printing the Array Values
  4. Associative Arrays
  5. The Multidimensional Array
  6. Beyond Multidimensional Arrays
By: James Payne
Rating: starstarstarstarstar / 6
January 07, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

You can also create arrays that are two-dimensional, three-dimensional, and so on. You could even have a fifth-dimensional array. If you don't want to kill yourself though, or some unfortunate programmer who has to come along and read your code in the future, then you may just want to max your arrays to the third-dimension.

Here is a sample of a quick two-dimensional array:


<html>

<body>

<?php


$soda = array( array(Type=>“Mountain Dew”,

Price=> 1.25,

Quantity=> 20)

),

array(Type=> “Pepsi”,

Price=> 1.25,

Quantity=> 22,

),

array(Type=>“Mello Yello”,

Price=>1.25,

Quantity=> 30

)

);

?>

In the above example we use Associative arrays inside our two-dimensional array to create the column names. Otherwise we would have to use numbers, and things would get really ugly.

Well, that's it for this tutorial. In the (eventual) next episode we will go over Loops inside of PHP. So come back often.

Till then...



 
 
>>> More PHP Articles          >>> More By James Payne
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: