Source code for:
challenge1_3.php
<html>
<head>
<title>Q7310 Challenge1.3 Using Arrays For a PhoneBook</title>
</head>
<BODY bgcolor="000000" link="#FFFF00" vlink="#FFFF00" alink="#00FF00" text="#ececec">
<h1 align="center">
Program #3 <br> Using Associative "Named Counter Variable" for Arrays
</h1>
<DIV align="center">
<FONT face="arial, helvetica, sans-serif" size=2 color="ececec">
<TABLE width="90%" border=1 cellpadding=10 cellspacing=0>
<TR>
<TD>
<?php
// INITIALIZE THE ARRAY, $testing
$testing = array(
"Program 1.3 ", "<br>", "Purpose: use ",
"named variable 'INDEX' called ",
"an ASSOCIATIVE ARRAY counter ",
"to produce a simple phone directory."
);
// SET THE MAXIMUM TIMES TO REPEAT: $times
// INITIALIZE THE ARRAY INDEX at 0 (element #1)
$times = count($testing);
// FOR LOOPING
FOR ($x=0; $x < $times; ++$x) {
print $testing[$x];
}
// ====================================================================
?>
</TD>
</TR>
<TR>
<TD>
<?php
// INITIALIZE PHONE DIRECTORY ARRAY
$character = array (
array (
"name" => "C.Mack",
"sport" => "WBB",
"course" => "Mentoring",
"time" => "Su 7 pm",
"phone" => "573-999-9999"
),
array (
"name" => "C.S.James",
"sport" => "WBB",
"course" => "Mentoring, Ag Econ & Educ",
"time" => "Su 7 pm, M W11 am, T 10:15 am, R 8:45 am ",
"phone" => "573-999-9999"
),
array (
"name" => "K.Anderson",
"sport" => "Gymnastics",
"course" => "Acctg 36",
"time" => "M 9 am",
"phone" => "573-999-9999"
),
array (
"name" => "S.Simons",
"sport" => "WSB",
"course" => "C&IV",
"time" => "M 10:15 am",
"phone" => "573-999-9999"
),
array (
"name" => "J.Scott",
"sport" => "FB",
"course" => "Personal Finance",
"time" => "M 11 am",
"phone" => "573-999-9999"
),
array (
"name" => "S.Paffrath",
"sport" => "FB",
"course" => "Ag Econ",
"time" => "T 10:15 am",
"phone" => "573-999-9999"
),
array (
"name" => "J.Humprey",
"sport" => "FB",
"course" => "C&IV",
"time" => "T 1:15 pm",
"phone" => "573-999-9999"
),
array (
"name" => "E.Goldsmith",
"sport" => "FB",
"course" => "C&IV",
"time" => "W 11 am",
"phone" => "573-999-9999"
),
array (
"name" => "M.Rucker",
"sport" => "FB",
"course" => "Ag Computing",
"time" => "W 11:45 am",
"phone" => "573-999-9999"
),
array (
"name" => "T.Omboga",
"sport" => "FB",
"course" => "Ag Econ",
"time" => "W 12:30 pm",
"phone" => "573-999-9999"
),
array (
"name" => "A.Britt",
"sport" => "FB",
"course" => "Ag Econ",
"time" => "W 1:15 pm",
"phone" => "573-999-9999"
),
array (
"name" => "T.Woodley",
"sport" => "WR",
"course" => "Ag Econ",
"time" => "T R 1:30 pm",
"phone" => "573-999-9999"
),
array (
"name" => "L.E. Grice",
"sport" => "Soccer",
"course" => "Statistics",
"time" => "R am",
"phone" => "573-999-9999"
),
array (
"name" => "__________",
"sport" => "________",
"course" => "Open Session",
"time" => "R F by appointment",
"phone" => "573-999-9999"
),
);
?>
<?php
// ***** PRINT ROUTINE ****************************************
$pArray=(array)$pArray; // transfer data to an Array for printing
// print gettype($pArray); echo " ";
$pLine = " "; // array (row) contents
// print gettype($pLine); echo " ";
$pIndex = " "; // associative index = field label
// print gettype($pIndex);
?>
<FONT color="gold">
<h2 align="center">My TPP Student Directory </h2>
</FONT>
<?php
$r=1;
$c=0;
foreach ( $character as $pArray )
{
Print "$r"; echo ". ";
foreach ( $pArray as $pIndex=>$pLine )
{
IF ($c==0) {
echo "<b>"; echo "<FONT color='gold'>";
print "$pLine <br>";
echo "</b>"; echo "</FONT>";
}ELSE{
Print "$pIndex: $pLine <br>";
}
$c=$c+1;
}
print "<br>";
$r=$r+1; //increment row counter
$c=0; //re-initialize "column" or field indicator
}
?>
</TD>
</TR>
<TR>
<TD>
<?php
?>
</TD>
</TR>
<TR>
<TD>
SOURCE CODE: Click
<A HREF="http://rrchubbard.org/php/q7310/source1_3.php" target="_blank">
HERE </A>
</TD>
</TR>
</TABLE>
</FONT>
</DIV>
[<A href="top" target="_self">Top</A>]
<BR>
Last Updated
<I>:
<!-- #BeginDate format:fcAm1m -->Tuesday, September 28, 2004 16:59<!-- #EndDate -->
</I>
<P>
<FONT face="Arial, Helvetica, sans-serif" size="1">
(c) 2004 Robin Y. Mabry Hubbard <A href="mailto:4ascii@marz.com">4ascii@marz.com</A>
</FONT>
</P>
</body>
</html>
|