PHP: The Switch Statement and Arrays - Beyond Multidimensional Arrays (Page 6 of 6 )
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...
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |