StUdY GuiDe

Reference links

ReLaTeD

Other links

* Notes *

Look-up a function in the PHP manual as www.php.net/function_name
Examples:
www.php.net/count
www.php.net/array_merge

Chapters Seven - Eight - Nine

In a Nutshell

PHP Version: 5.2.8


Main Content

<div id="floatRight">
<div id="mainContentHeader">
<h2>Chapters Seven - Eight - Nine</h2>
<p>In a Nutshell</p>
</div><!-- close #mainContentHeader -->

<div id="mainContent">

<div id="left">

<div id="banner">
<img src="images/phpftwww.png" height="521" width="23" alt="" />
</div><!--close #banner-->
</div><!--close #left-->

<div id="right">

<h2 class="first">Chapter Seven (exercise one)</h2>
<p>Adding items to an array.</p>

<p>
<?php
$soups 
= array (
'Monday' => 'Clam Chowder',
'Tuesday' => 'White Chicken Chili',
'Wednesday' => 'Vegetarian'
);

print_r ($soups);

// Count and print the current number of elements.
$number1 count ($soups);
print 
"<p>The soups array originally had $number1 elements.</p>";

// Add three items to the array.
$soups['Thursday'] = 'Chicken Noodle';
$soups['Friday'] = 'Tomato';
$soups['Saturday'] = 'Cream of Broccoli';

// Count and print the number of elements again.
$number2 count ($soups);
print 
"<p>After adding 3 more soups, the array now has $number2 elements.</p>";

print_r ($soups);
?>
</p>

<h2 class="first">Chapter Seven (exercise two)</h2>
<p>Accessing array elements.</p>

<p>
<?php
//Print each key and value.
foreach ($soups as $key => $value) {
    print 
"Key is $key. Value is $value.<br />";
}
?>
</p>
<p>
<?php
//Print each key and value.
foreach ($soups as $day => $soup) {
print 
"$day: $soup<br />\n";
}
?>
</p>


</div><!--close right-->

</div><!-- close #mainContent -->
</div><!--close #floatRight-->

Source Code for Current Page

<?php $page="seven-nine"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Chapt. 7-9 Exercise</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/common/php.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrap">

<!-- Heading -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/h1.php'); ?>

<!-- Top Navigation Bar -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/bar-nav.php'); ?>

<!-- Related Links -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/h3.php'); ?>

<!-- Main Content -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/' $page '.php'); ?>

<!-- Bottom Navigation Bar -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/bar-nav2.php'); ?>

<!-- Foot -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/foot.php'); ?>
</div><!-- close #wrap -->

<!-- Show Source -->

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/source.php'); ?>
</body>

</html>


Head

<div id="head">
<p>Lzydaz.com</p>
<div id="heading">
<h1 id="top">PHP Study Group</h1>
<p>This page is designed as a study tool for the book<br />
<cite><a href="http://www.dmcinsights.com/phpvqs2">PHP for the World Wide Web by Larry Ullman (2nd Edition)</a></cite></p>
</div><!--close #heading-->
<img src="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/images/logo.png" height="67" width="100" alt="logo" />
</div><!-- close #head -->
<div id="head-edge">
<!--IE hates this-->
</div><!--close #head-edge-->

Navigation Bar

<div id="nav-top">
<?php $currentPage basename ($_SERVER['PHP_SELF']); ?>
<ul>
<li>
<a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/index.php" title="PHP Study Group Index"
<?php
if($currentPage=="index.php"){
    print 
'class="current"';
}
?>
    >Chapter Index</a><!--close anchor tag-->
    </li>
<li>
<a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/chapt1-3.php" title="Chapters One - Three"
<?php
if($currentPage=="chapt1-3.php"){
    print 
'class="current"';
}
?>
    >One - Three</a><!--close anchor tag-->
    </li>
    <li>
<a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/chapt4-6.php" title="Chapters Four - Six"
<?php
if($currentPage=="chapt4-6.php"){
    print 
'class="current"';
}
?>
    >Four - Six</a><!--close anchor tag-->
    </li>
    <li>
<a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/chapt7-9.php" title="Chapters Seven - Nine"
<?php
if($currentPage=="chapt7-9.php"){
    print 
'class="current"';
}
?>
    >Seven - Nine</a><!--close anchor tag-->
    </li>
    <li>
<a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/studygroup/php/chapt10-13.php" title="Chapters Ten - Thirteen"
<?php
if($currentPage=="chapt10-13.php"){
    print 
'class="current"';
}
?>
    >Ten - Thirteen</a><!--close anchor tag-->
    </li>
    </ul>
    </div> <!-- close #nav-top -->

Related Links

<div id="floatLeft">
<div id="sideHeader1">
<h3>StUdY GuiDe</h3>
<p><em>Reference links</em></p>
</div><!-- close #sideHeader1 -->

<div id="side1">
<p><a href="http://www.php.net/manual" title="php.net">PHP Functions Manual</a></p>
</div><!-- close #side1 -->

<div id="sideHeader2">
<h3>ReLaTeD</h3>
<p><em>Other links</em></p>
</div><!-- close #sideHeader2 -->

<div id="side2">
<p><a href="<?php ($_SERVER['DOCUMENT_ROOT']); ?>/phpBB3/index.php" title="Hello World">Forum</a></p>
<p><a href="http://rjoannej.com/ullmanBook/index.php" title="Joanne's Index">Joanne's Page</a></p>
<p><a href="http://krisse.tuna.fi/phpwww/index.php" title="Krisse's Index">Krisse's Page</a></p>
<p><a href="http://www.amaraland.com/studyGroup/index.php" title="KC's Index">KC's Page</a></p>

</div><!-- close #side2 -->

<div class="side3">

<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/notes/note-' $page '.php'); ?>

</div><!--close #side3-->
</div><!--close #floatLeft-->

Foot

<div id="foot-edge">
<!--IE hates this-->
</div><!--close #foot-edge-->

<div id="foot">
<?php include($_SERVER['DOCUMENT_ROOT'] . '/studygroup/php/includes/copyright.php'); ?>
<p><a href="http://validator.w3.org/check?uri=referer" rel="nofollow" title="XHTML Validator">XHTML</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer" title="CSS Validator" rel="nofollow">CSS</a></p>
</div><!--close #foot-->

Copyright

<p>Bonnie Lincicome &copy; <?php echo date('Y');?> All Rights Reserved<br />
This page was last updated on <?php echo date('F d, Y H:i:s'getlastmod($filename)); ?></p>

Back to the Top