Immediate download Solution Manual for PHP Programming with MySQL The Web Technologies Series, 2nd Edition all chapters
Immediate download Solution Manual for PHP Programming with MySQL The Web Technologies Series, 2nd Edition all chapters
http://testbankbell.com/product/test-bank-for-php-programming-with-
mysql-the-web-technologies-series-2nd-edition/
http://testbankbell.com/product/solution-manual-for-introduction-to-
javascript-programming-with-xml-and-php-0133068307/
http://testbankbell.com/product/test-bank-for-introduction-to-
javascript-programming-with-xml-and-php-0133068307/
http://testbankbell.com/product/test-bank-for-fundamentals-of-java-ap-
computer-science-essentials-4th-edition-by-lambert/
Test Bank for The Complete Textbook of Phlebotomy 5th
Edition by Hoeltke
http://testbankbell.com/product/test-bank-for-the-complete-textbook-
of-phlebotomy-5th-edition-by-hoeltke/
http://testbankbell.com/product/test-bank-for-south-western-federal-
taxation-2015-individual-income-taxes-38th-edition/
http://testbankbell.com/product/cases-in-finance-3rd-edition-demello-
solutions-manual/
http://testbankbell.com/product/test-bank-for-sensation-and-
perception-second-edition/
http://testbankbell.com/product/advanced-financial-accounting-baker-
christensen-cottrell-9th-edition-test-bank/
Test Bank for Principles of Healthcare Reimbursement 5th
Edition by Casto
http://testbankbell.com/product/test-bank-for-principles-of-
healthcare-reimbursement-5th-edition-by-casto/
PHP Programming with MySQL, 2nd Edition 2-1
Chapter 2
Functions and Control Structures
At a Glance
Table of Contents
Chapter Overview
Chapter Objectives
Instructor Notes
Quick Quizzes
Discussion Questions
Key Terms
PHP Programming with MySQL, 2nd Edition 2-2
Lecture Notes
Chapter Overview
In this chapter, students will study how to use functions to organize their PHP code. They will
also learn about variable scope, nested control structures, and conditional coding: if, if…else,
and switch statements and while, do…while, for, and foreach looping statements.
Students will also be introduced to the include and require statements.
Chapter Objectives
In this chapter, students will:
Instructor Notes
In PHP, groups of statements that you can execute as a single unit are called functions. Functions
are often made up of decision-making and looping statements. These are two of the most
fundamental statements that execute in a program.
Defining Functions
To begin writing a function, you first need to define it. The syntax for the function definition is:
Parameters are placed within the parentheses that follow the function name. The parameter
receives its value when the function is called. When you name a variable within parentheses, you
do not need to explicitly declare and initialize the parameter as you do with a regular variable.
Following the parentheses that contain the function parameters is a set of curly braces, called
function braces, which contain the function statements. Function statements are the statements
that do the actual work of the function and must be contained within the function braces. For
example:
function displayCompanyName($Company1) {
echo "<p>$Company1</p>";
}
Remind your students that functions, like all PHP code, must be contained with
<?php...?> tags. Stress that the function name should be descriptive of the
task that the function will perform.
Ask students to add this to their list of PHP “Best Coding Practices.”
Ask students to add this to their list of PHP “Best Coding Practices.”
PHP Programming with MySQL, 2nd Edition 2-4
Calling Functions
A function definition does not execute automatically. Creating a function definition only names
the function, specifies its parameters (if any), and organizes the statements it will execute.
Teaching Refer to the textbook example on page 77, which defines a function and calls it
Tip passing a literal value to the function argument.
Returning Values
Some functions return a value, which may be displayed or passed as an argument to another
function. A calculator function is a good example of a return value function. A return statement
is a statement that returns a value to the statement that called the function.
Use the textbook example on page 78 to illustrate how a calling statement calls a
Teaching function and sends the multiple values as arguments of the function. The
Tip function then performs a calculation and returns the value to the calling
statement.
Usually, the value of a variable is passed as the parameter of a function, which means that a local
copy of the variable is created to be used by the function. When the value is returned to the
calling statement, any changes are lost. If you want the function to change the value of the
parameter, you must pass the value by reference, so the function works on the actual value
instead of a copy. Any changes made by the function statements remain after the function ends.
Teaching Explain to students that a function definition should be placed above any calling
Tip statements. As of PHP4, this is not required, but is considered a good
programming practice.
Ask students to add this to their list of PHP “Best Coding Practices.”
PHP Programming with MySQL, 2nd Edition 2-5
When you use a variable in a PHP program, you need to be aware of the variable's scope—that
is, you need to think about where in your program a declared variable can be used. A variable's
scope can be either global or local. Global variables are declared outside a function and are
available to all parts of the programs. Local variables are declared inside a function and are only
available within the function in which they are declared.
Unlike many programming languages that make global variables automatically available to all
parts of your program, in PHP, you must declare a global variable with the global keyword
inside a function for the variable to be available within the scope of that function. When you
declare a global variable with the global keyword, you do not need to assign a value, as you
do when you declare a standard variable. Instead, within the declaration statement you only need
to include the global keyword along with the name of the variable, as in:
global $variable_name;
Teaching Demonstrate the syntax of declaring a global variable within a function using the
Tip textbook example on page 83.
Quick Quiz 1
1. In PHP, groups of statements that you can execute as a single unit are called
_________________________.
ANSWER: functions
Making Decisions
In any programming language, the process of determining the order in which statements execute
in the program is called decision making or flow control. The special types of PHP statements
used for making decision are called decision-making statements or control structures.
if Statements
You should insert a space after the conditional keyword if before the opening
parenthesis of the conditional expression. This will help you see a visual
difference between a structure and a function. Using a line break and
indentation to enter the statements to execute makes it easier for the
programmer to follow the flow of the code.
Ask students to add the space and indentation to their list of PHP “Best Coding
Teaching Practices.”
Tip
Explain to students that if there is only one statement, they do not need to use
curly braces. If there are multiple statements, the statements should be
enclosed within beginning and ending curly braces. ({...}).
Ask students to add the use of curly braces to their list of PHP “Best Coding
Practices.”
You can use a command block to construct a decision-making structure using multiple if
statements. A command block is a group of statements contained within a set of braces, similar to
the way function statements are contained within a set of braces. When an if statement
evaluates to TRUE, the statements in the command block execute.
if...else Statements
Should you want to execute one set of statements when the condition evaluates to FALSE, and
another set of statements when the condition evaluates to TRUE, you need to add an else
clause to the if statement.
PHP Programming with MySQL, 2nd Edition 2-7
if (conditional expression) {
statements; //condition evaluates to 'TRUE'
}
else {
statements; //condition evaluates to 'FALSE'
}
switch Statements
The switch statement controls program flow by executing a specific set of statements,
depending on the value of the expression. The switch statement compares the value of an
expression to a value contained within a special statement called a case label. A case label
represents a specific value and contains one or more statements that execute if the value of the
case label matches the value of the switch statement’s expression. The syntax for the switch
statement is a follows:
PHP Programming with MySQL, 2nd Edition 2-8
switch (expression) {
case label:
statement(s);
break;
case label:
statement(s);
break;
...
default:
statement(s);
break;
}
Another type of label used within switch statements is the default label. The default
label contains statements that execute when the value returned by the switch statement does
not match a case label. A default label consists of the keyword default followed by a
colon. In a switch statement, execution does not automatically end when a matching label is
found. A break statement is used to exit a control structures before it reaches the closing brace
(}). A break statement is also used to exit while, do...while, and for looping
statements.
The break statement after the default case is optional; however, it is good
Teaching programming practice to include it.
Tip
Ask the students to add this to their list of PHP “Best Coding Practices.”
PHP Programming with MySQL, 2nd Edition 2-9
Quick Quiz 2
1. The process of determining the order in which statements execute in a program is called
_________________________.
ANSWER: decision-making or flow control
Repeating Code
Conditional statements allow you select only a single branch of code to execute and then
continue to the statement that follows. If you need to perform the same statement more than
once, however, you need a use a loop statement, a control structure that repeatedly executes a
statement or a series of statements while a specific condition is TRUE or until a specific
condition becomes TRUE. In an infinite loop, a loop statement never ends because its conditional
expression is never FALSE.
while Statements
The while statement is a simple loop statement that repeats a statement or series of statements
as long as a given conditional expression evaluates to TRUE. The syntax for the while statement
is as follows:
Each repetition of a looping statement is called an iteration. The loop ends and the next
statement, following the while statement executes only when the conditional statement
evaluates to FALSE. You normally track the progress of the while statement evaluation, or
any other loop, with a counter. A counter is a variable that increments or decrements with each
iteration of a loop statement.
PHP Programming with MySQL, 2nd Edition 2-10
do...while Statements
The do...while statement executes a statement or statements once, then repeats the execution
as long as a given conditional expression evaluates to TRUE The syntax for the do...while
statement is as follows:
do {
statements(s);
} while (conditional expression);
for Statements
The for statement is used for repeating a statement or series of statements as long as a given
conditional expression evaluates to TRUE. The syntax of the for statement is as follows:
foreach Statements
The foreach statement is used to iterate or loop through the elements in an array. With each
loop, a foreach statement moves to the next element in an array. The basic syntax of the
foreach statement is as follows:
Quick Quiz 3
3. The foreach statement is used to iterate or loop through the elements in a(n)
_________________________.
ANSWER: array
Discussion Questions
When is it better to use a global variable in programming? When is it better to use a local
variable?
Key Terms
break statement: Used to exit control structures.
case label: In a switch statement, represents a specific value and contains one or more
statements that execute if the value of the case label matches the value of the switch
statement’s expression.
command block: A group of statements contained within a set of braces, similar to the way
function statements are contained within a set of braces.
counter: A variable that increments or decrements with each iteration of a loop statement.
decision making (or flow control): The process of determining the order in which
statements execute in a program.
default label: Contains statements that execute when the value returned by the switch
statement expression does not match a case label.
do…while statement: Executes a statement or statements once, then repeats the execution
as long as a given conditional expression evaluates to TRUE.
for statement: Used for repeating a statement or series of statements as long as a given
conditional expression evaluates to TRUE.
function definition: Line of code that make up a function.
functions: Groups of statements that execute as a single unit.
global variable: A variable declared outside a function and available to all parts of the
program.
if statement: Used to execute specific programming code if the evaluation of a conditional
expression returns a value of TRUE.
if…else statement: if statement with an else clause that is implemented when the
condition returns a value of FALSE.
infinite loop: A loop statement never ends because its exit condition is never met.
iteration: The repetition of a looping statement.
local variable: A variable declared inside a function and only available with the function in
which it is declared.
loop statement: A control structure that repeatedly executes a statement or a series of
statements while a specific condition is TRUE or until a specific condition becomes TRUE.
nested decision-making structures: One decision-making statement contained within
another decision-making statement.
parameter: A variable that is passed to a function from the calling statement.
return statement: A statement that returns a value to the statement that called the function.
switch statement: Controls program flow by executing a specific set of statements,
depending on the value of an expression.
variable scope: The context in which a variable is accessible (such as local or global).
while statement: Repeats a statement or a series of statements as long as a given conditional
expression evaluates to TRUE.
PHP Programming with MySQL, 2nd Edition 2-13
Title: Social devices for impelling women to bear and rear children
Language: English
LETA S. HOLLINGWORTH
Bellevue Hospital, New York City
“Again, the breeding function of the family would be better discharged if public
opinion and religion conspired, as they have until recently, to crush the aspirations
of woman for a life of her own. But the gain would not be worth the price.”—E. A.
Ross, Social Control (1904).
Children add to the weight of the struggle for existence of their parents. The
relation of parent to child is one of sacrifice. The interests of parents and children
are antagonistic. The fact that there are or may be compensations does not affect
the primary relation between the two. It may well be believed that, if procreation
had not been put under the dominion of a great passion, it would have been caused
to cease by the burdens it entails.
effected by means of types or patterns, which society induces its members to adopt
as their guiding ideals.... To this end are elaborated various patterns of conduct
and of character, which may be termed social types. These types may become in
the course of time personal ideals, each for that category of persons for which it is
intended.
For women, obviously enough, the first and most primitive “zone
of requirement” is and has been to produce and rear families large
enough to admit of national warfare being carried on, and of
colonization.
Thus has been evolved the social type of the “womanly woman,”
“the normal woman,” the chief criterion of normality being a
willingness to engage enthusiastically in maternal and allied
activities. All those classes and professions which form “the radiant
points of social control” unite upon this criterion. Men of science
announce it with calm assurance (though failing to say on what kind
or amount of scientific data they base their remarks). For instance,
McDougall[2] writes:
The highest stage is reached by those species in which each female produces at
birth but one or two young, and protects them so efficiently that most of the young
born reach maturity; the maintenance of the species thus becomes in the main the
work of the parental instinct. In such species the protection and cherishing of the
young is the constant and all-absorbing occupation of the mother, to which she
devotes all her energies, and in the course of which she will at any time undergo
privation, pain, and death. The instinct (maternal instinct) becomes more powerful
than any other, and can override any other, even fear itself.
... charm is the technique of the maiden, and sacrifice the passion of the mother.
One set of feminine interests expresses more distinctly the issues of courtship and
attraction; the other of qualities of motherhood and devotion.
Only abnormal women want no babies. Trenchant criticism of modern life was
made by Dr. Max G. Schlapp, internationally known as a neurologist. Dr. Schlapp
addressed his remarks to the congregation of the Park Avenue M.E. Church. He
said, “The birth rate is falling off. Rich people are the ones who have no children,
and the poor have the greatest number of offspring. Any woman who does not
desire offspring is abnormal. We have a large number, particularly among the
women, who do not want children. Our social society is becoming intensely
unstable.”
Normally woman lives through her children; man lives through his work.
Scores of such implicit attempts to determine and present the type
or norm meet us on every hand. This norm has the sanction of
authority, being announced by men of greatest prestige in the
community. No one wishes to be regarded by her fellow-creatures as
“abnormal” or “decayed.” The stream of suggestions playing from all
points inevitably has its influence, so that it is or was, until recently,
well-nigh impossible to find a married woman who would admit any
conflicting interests equal or paramount to the interest of caring for
children. There is a universal refusal to admit that the maternal
instinct, like every other trait of human nature, might be distributed
according to the probability curve.
Public opinion.—Let us turn next to public opinion as a means of
control over women in relation to the birth rate. In speaking of
public opinion Ross says:
Haman is at the mercy of Mordecai. Rarely can one regard his deed as fair when
others find it foul, or count himself a hero when the world deems him a wretch....
For the mass of men the blame and the praise of the community are the very lords
of life.
M. Emil Reymond has made this melancholy announcement in the Senate: “We
are living in an age when women have pronounced upon themselves a judgment
that is dangerous in the highest degree to the development of the population.... We
have the right to do what we will with the life that is in us, say they.”
Thus the desire for the development of interests and aptitudes
other than the maternal is stigmatized as “dangerous,” “melancholy,”
“degrading,” “abnormal,” “indicative of decay.” On the other hand,
excessive maternity receives many cheap but effective rewards. For
example, the Jesuit priests hold special meetings to laud maternity.
The German Kaiser announces that he will now be godfather to
seventh, eighth, and ninth sons, even if daughters intervene. The ex-
President has written a letter of congratulation to the mother of nine.
Law.—Since its beginning as a human institution law has been a
powerful instrument for the control of women. The subjection of
women was originally an irrational consequence of sex differences in
reproductive function. It was not intended by either men or women,
but simply resulted from the natural physiological handicaps of
women, and the attempts of humanity to adapt itself to physiological
nature through the crude methods of trial and error. When law was
formulated, this subjection was defined, and thus furthered. It would
take too long to cite all the legal provisions that contribute,
indirectly, to keep women from developing individualistic interests
and capacities. Among the most important indirect forces in law
which affect women to keep them child-bearers and child-rearers
only are those provisions that tend to restrain them from possessing
and controlling property. Such provisions have made of women a
comparatively possessionless class, and have thus deprived them of
the fundamentals of power. While affirming the essential nature of
woman to be satisfied with maternity and with maternal duties only,
society has always taken every precaution to close the avenues to
ways of escape therefrom.
Two legal provisions which bear directly on women to compel
them to keep up the birth rate may be mentioned here. The first of
these is the provision whereby sterility in the wife may be made a
cause of divorce. This would be a powerful inducement to women
who loved their husbands to bear children if they could. The second
provision is that which forbids the communication of the data of
science in the matter of the means of birth control. The American
laws are very drastic on this point. Recently in New York City a man
was sentenced to prison for violating this law. The more advanced
democratic nations have ceased to practice military conscription.
They no longer conscript their men to bear arms, depending on the
volunteer army. But they conscript their women to bear children by
legally prohibiting the publication or communication of the
knowledge which would make child-bearing voluntary.
Child-rearing is also legally insured by those provisions which
forbid and punish abortion, infanticide, and infant desertion. There
could be no better proof of the insufficiency of maternal instinct as a
guaranty of population than the drastic laws which we have against
birth control, abortion, infanticide, and infant desertion.
Belief.—Belief, “which controls the hidden portions of life,” has
been used powerfully in the interests of population. Orthodox
women, for example, regard family limitation as a sin, punishable in
the hereafter. Few explicit exhortations concerning the birth rate are
discoverable in the various “Words” of God. The belief that family
limitation will be punished in the hereafter seems to have been
evolved mainly by priests out of the slender materials of a few
quotations from Holy Writ, such as “God said unto them, ‘Multiply
and replenish the earth,’” and from the scriptural allusion to children
as the gifts of God. Being gifts from God, it follows that they may not
be refused except at the peril of incurring God’s displeasure.
Education.—The education of women has always, until the end of
the nineteenth century, been limited to such matters as would
become a creature who could and should have no aspirations for a
life of her own. We find the proper education for girls outlined in the
writings of such educators as Rousseau, Fénelon, St. Jerome, and in
Godey’s Lady’s Book. Not only have the “social guardians” used
education as a negative means of control, by failing to provide any
real enlightenment for women, but education has been made a
positive instrument for control. This was accomplished by drilling
into the young and unformed mind, while yet it was too immature to
reason independently, such facts and notions as would give the girl a
conception of herself only as future wife and mother. Rousseau, for
instance, demanded freedom and individual liberty of development
for everybody except Sophia, who was to be deliberately trained up
as a means to an end. In the latter half of the nineteenth century
when the hard battle for the real enlightenment of women was being
fought, one of the most frequently recurring objections to admitting
women to knowledge was that “the population would suffer,” “the
essential nature of woman would be changed,” “the family would
decay,” and “the birth rate would fall.” Those in control of society
yielded up the old prescribed education of women only after a
stubborn struggle, realizing that with the passing of the old training
an important means of social control was slipping out of their hands.
Art.—A very long paper might be written to describe the various
uses to which art has been put in holding up the ideal of
motherhood. The mother, with children at her breast, is the favorite
theme of artists. The galleries of Europe are hung full of Madonnas
of every age and degree. Poetry abounds in allusions to the
sacredness and charm of motherhood, depicting the yearning of the
adult for his mother’s knee. Fiction is replete with happy and adoring
mothers. Thousands of songs are written and sung concerning the
ideal relation which exists between mother and child. In pursuing
the mother-child theme through art one would not be led to suspect
that society finds it necessary to make laws against contra-
conception, infanticide, abortion, and infant desertion. Art holds up
to view only the compensations of motherhood, leaving the other half
of the theme in obscurity, and thus acting as a subtle ally of
population.
Illusion.—This is the last of Ross’s categories to which I wish to
refer. Ross says:
In the taming of men there must be provided coil after coil to entangle the
unruly one. Mankind must use snares as well as leading-strings, will-o-the-wisps
as well as lanterns. The truth by all means, if it will promote obedience, but in any
case obedience! We shall examine not creeds now, but the films, veils, hidden
mirrors, and half lights by which men are duped as to that which lies nearest them,
their own experience. This time we shall see men led captive, not by dogmas
concerning a world beyond experience, but by artfully fostered misconceptions of
the pains, satisfactions, and values lying under their very noses.
There is no evidence that the death rate of women from child-birth has caused
the governing classes many sleepless nights.
Anthony gives some statistics from Prussia (where the figures have
been calculated), showing that
between 1891 and 1900 11 per cent of the deaths of all women between the ages of
twenty-five and forty years occurred in child-birth.... During forty years of peace
Germany lost 400,000 mothers’ lives, that is, ten times what she lost in soldiers’
lives in the campaign of 1870 and 1871.
One who learns why society is urging him into the straight and narrow way will
resist its pressure. One who sees clearly how he is controlled will thenceforth be
emancipated. To betray the secrets of ascendancy is to forearm the individual in
his struggle with society.
The time is coming, and is indeed almost at hand, when all the
most intelligent women of the community, who are the most
desirable child-bearers, will become conscious of the methods of
social control. The type of normality will be questioned; the laws will
be repealed and changed; enlightenment will prevail; belief will be
seen to rest upon dogmas; illusion will fade away and give place to
clearness of view; the bugaboos will lose their power to frighten. How
will “the social guardians” induce women to bear a surplus
population when all these cheap, effective methods no longer work?
The natural desire for children may, and probably will, always
guarantee a stationary population, even if child-bearing should
become a voluntary matter. But if a surplus population is desired for
national aggrandizement, it would seem that there will remain but
one effective social device whereby this can be secured, namely,
adequate compensation, either in money or in fame. If it were
possible to become rich or famous by bearing numerous fine
children, many a woman would no doubt be eager to bring up eight
or ten, though if acting at the dictation of maternal instinct only, she
would have brought up but one or two. When the cheap devices no
longer work, we shall expect expensive devices to replace them, if the
same result is still desired by the governors of society.
If these matters could be clearly raised to consciousness, so that
this aspect of human life could be managed rationally, instead of
irrationally as at present, the social gain would be enormous—
assuming always that the increased happiness and usefulness of
women would, in general, be regarded as social gain.
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
testbankbell.com