Note that these problems are intended as a review and NOT as sample problems.
Write a recursive function that finds the sum of squares up to a given number n (passed as a parameter). Below 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 sum squares
Author: Elena Machkasova elenam@morris.umn.edu
Last modified: 4/21/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 sum squares
</title>
<?php
// the function goes here
?>
</head>
<body>
<p>
<?php
// function call goes here
?>
</p>
</body>
</html>
http://csci1101sp10.morris.umn.edu/~elenam/1101_spring10/review2/recursion.php
Log in to PhpMyAdmin and write and test the following queries:
Write the following queries (you may test them in your own database):
Write regular expressions for the following patterns:
You may test them here: http://www.spaweditor.com/scripts/regex/index.php. Important: please set type to POSIX. Note that the default is case-insensitive.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Recursive array printing - as nested lists
Author: Elena Machkasova elenam@morris.umn.edu
Last modified: 4/21/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 -- as nested lists
</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) {
print "<ol>";
foreach($array as $item) {
if (!is_array($item)) {
print "<li>$item</li>";
} else {
print_nested_array($item);
}
}
print "</ol>\n";
}
?>
</head>
<body>
<?php
$strings = array("Level one", array("Level two", "Another level two","A thread at level two", array("Level three", "More level three")),
"Back to level one again");
//print "<pre>";
//print_r($strings);
//print "</pre>";
print_nested_array($strings);
?>
</body>
</html
http://csci1101sp10.morris.umn.edu/~elenam/1101_spring10/review2/array_printing_as_lists.php
Use the following program as a starting point. Recall that unset
removes an element. Also note that in order to change an array you must
pass it by reference (using &)
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Write a function that removes all occurrences of an element
from an array
Author: Elena Machkasova
Last modified: 4/22/08
-->
<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>
Write a function that removes all occurrences of an element
from an array
</title>
<?php
$stuff = array("apples", "oranges", "more apples", "oranges",
"bananas", "kiwi", "apples", "strawberries");
function print_array($the_array) {
print "<p>";
foreach ($the_array as $element) {
print "$element ";
}
print "</p>\n";
}
// write the function "remove" that takes an array and an element
// and removes all copies of the element from the array
?>
</head>
<body>
<h3>Write a function that removes all occurrences of an element
from an array </h3>
<?php
print_array($stuff);
// call the function to remove "apples" from the array, print it out
// call the function to remove "kiwi" from the array, print it out
// call the function that to remove "radishes" (or somehing else that's NOT in
// the array), print out the array
?>
</body>
</html>
http://csci1101sp10.morris.umn.edu/~elenam/1101_spring10/review2/array_remove.php