Log in

View Full Version : Array Help



thanhtan
12-14-2008, 05:23 PM
Hi all,

I was going through some php tutorials and on the topic of arrays...

To create an array you simply use the following syntax:
$myArray = array("value", "value", "value);
OR
$myArray2 = array("value", array("value");

So my question is: is the second one a two dimensional array?
because you could reff. myArray2 with $myArray2[0][0];

If yes... How could you set up the array structure to contain for example, category names and data within a category name...but have several different listings for a given category?

Thanks.
_______________________________________________
welcome to best contact lens coupons (http://www.bestcontactlenscoupons.com/)

techietim
12-14-2008, 07:20 PM
$var = array(
'client' => array(
'js',
'css'
),
'server' => array(
'php',
'jsp'
)
);
//$var['server'][0] = PHP
//$var['client'][1] = CSS

Twey
12-15-2008, 05:53 AM
PHP doesn't really have support for multidimensional arrays. It just uses arrays of arrays, which is what that example is (once the missing bracket is added) — an array with an array as one of its elements.

james438
12-15-2008, 06:10 AM
PHP doesn't really have support for multidimensional arrays. It just uses arrays of arrays, which is what that example is (once the missing bracket is added) — an array with an array as one of its elements.

I thought that is what multidimensional arrays were.

Twey
12-15-2008, 07:05 AM
No — some languages, such as Visual Basic and Haskell, have support for actual multidimensional arrays: a single array which takes as its key multiple values (or a tuple, in the case of Haskell). In homogenous arrays this is a rather cosmetic difference, but PHP arrays are heterogenous: they can contain different types, including mixing scalar values and other arrays, so it becomes rather important.