A multidimensional array holds recursively-defined arrays of arrays of data items. Typically, these items are selected and accessed via a sequence of integer indices.
The program below creates an empty two-dimensional array called: $saaSacraments. This array is stores the category in the first entry of the subarray and the sacraments in the subsequent entries.
<?php
$saaSacraments = array(
array("Initiation", "Baptism", "Confirmation", "Eucharist"),
array("Healing", "Reconciliation", "Anointing of the Sick"),
array("Service", "Holy Orders", "Matrimony")
);
// Loop over the entries of the array and print them
foreach ($saaSacraments as $sCategory) {
echo "The Sacraments of <b>".$sCategory[0]."</b> are<br />";
$iCount = count($sCategory);
for ($i = 1; $i < $iCount; ++$i) {
echo "{$sCategory[$i]}<br />";
}
echo "<br />";
}
?>
© 20072024 XoaX.net LLC. All rights reserved.