CSci 1101 Lab 8. Thursday, April 22. Due Monday, April 26th

Work in groups of two.

Recursive printing of a nested array

The task is to print out an array that has subarrays of an arbitrary nesting. Each next level of nesting should be indented relative to the previous one (similar to threads of comments). This is very similar to what you need to do for the project, except for the database access.

You might want to use <div> and CSS margin property for thsi task, but other approaches are fine as well.

Note: a substantial part of this lab is graded based on participation. Do not put more than 1 hour into this lab. Send me a link to your solution. If it doesn't work, write (in comments or in the e-mail message) what your next step would have been.

Here is the starting code:


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- 
Recursive array printing
Author: Elena Machkasova elenam@morris.umn.edu 
Last modified: 4/9/09
--> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>

CSci 1101: Recursive array printing
</title>
<?php
// the function is given an array that may 
// contain nested subarrays. The function
// prints the array elements indenting each level
function print_nested_array($array) {
  
}
?>
</head>
<body>
<?php
$strings = array("Level one", array("Level two", "Another level two"), 
array("Level two, second thread", array("Level three", "More level three")), 
"Back to level one again");
print "<pre>";
print_r($strings);
print "</pre>";
print_nested_array($strings);
?>
</body>

</html>

To submit

Send me an e-mail with the URL of the files when done, do not move the files after the submission. Make sure to CC your group partner.


CSci 1101 course web site.