I need to declare (not define) three dimensional array in PHP and then assign values to it.
For example,
<?php
$item = array(
array("item1", 22, 18),
array("Item2", 15, 13),
array("Item3", 5, 2),
);
?>
This is how I want my array. I first want to declare this $item
array and then assign those three values (e.g item1, 22, 18
) to it. Please help me with this and also how to access this array.
You said you wanted a three-dimensional array. The current array you have is two-dimensional.
What you might have meant was to have "item#" as a key to your array.
<?php
$item = array(
"item1" => array( 22, 18 ),
"Item2" => array( 15, 13 ),
"Item3" => array( 5, 2 ),
);
?>
You would access an element with $item['item1']
, which would give you the array (22,18)