I210 Midterm unlocked

¡Supera tus tareas y exámenes ahora con Quizwiz!

Array

An _________ is a data structure that can hold a set of ordered data represented by a single (reference) variable name. *Not a data type

NULL (example: $myVar;)

An uninitialized variable has the value of _________ in PHP.

Presentation layer Business layer Data layer

Application built on three-tier architecture consists of three separate, logical layers. What are they?

Automatically

Are type conversions/castings converted automatically or manually?

"require" displays a fatal error and immediately stops processing the script.

Define what "require" does when the file to be included is not found.

Element

Each item in an array is called an ____________.

iteration

Each repetition of a looping statement is called a(n) _____________.

Presentation layer: -A form that allows a student to enter his/her name, school ID, ... - The Web page that displays all grades. Business logic layer: retrieve student's name, id and send to the data server. Data layer: a server that stores every student's grades.

Example of a three-tier application: an application that allows a student to check his/her grades of all classes. Define each layer.

PHP VB.net and C#.net in ASP.net application Java in JSP or JSF applications Perl, Ruby, Python ......

Examples of server-side languages:

Single quoted: unparsed Double quoted: parsed NEVER mix single and double quotes. (echo 'Hello World!";) You may nest single and double quotations. Example: echo "Nancy said 'Hello World!' to the crowd.";

Explain the differences between the 3 different types of strings.

d) $value = 55;

Given a PHP variable named $value. The current value of the variable is 55. Which of the following answers does NOT return the boolean value TRUE?: a) $value == 55; b) $value === 55; c) $value >= 55; d) $value = 55;

The code will cause an infinite loop.

Given a block of PHP code for a while loop: $a = 0; while ($a < 5) { echo "$a "; } Which statement regarding the code above is correct?

d) $email = $_POST['email']

Given the code segment below: <form action="index.php" method="post"> <input type="text" name="email" /> </form> Which of the following code inside the index.php script will retrieve the content of the form element named email? a) $email = $_GET['email'] b) $email = $post("email); c) echo $email; d) $email = $_POST['email']

0.20

Given the following two PHP statements: $income = 72000; $tax_rate = ($income > 75000) ? 0.25 : 0.20; What is the value of $tax_rate after executing the two statements?

$number === $string;

Given the following two PHP statements: $number = 1990; $string = "1990"; Which of the following PHP statements returns "false"?

Naming a constant: Any valid identifiers; Does NOT begin with a dollar sign ($); Convention: use all uppercase letters. Example: define("CONSTANT_NAME", value);

How do we define constants?

denoted with a leading dollar sign ($). can be any length; can use letters, numbers or underscore(_); can not begin with a number; can not include spaces;

How do we define variables?

parsed

In PHP, a double-quoted string is also called a(n) ______ string.

boolean

In PHP, the data type that provides only two possible values (TRUE and FALSE) is called ______.

Integer: a whole number without decimals. Float: a number with a decimal point.

Integer v.s. Float (aka double)

e) None of the above

With file inclusion, we can store code in an external file so it can be shared across multiple PHP files. Which of the following can NOT be placed in an external file? a) PHP code that defines functions b) PHP code that defines constants c) PHP code that validates a user's credential. d) HTML code that creates a table e) None of the above

foreach (array as variable) { statements; } foreach (array as key => variable) { statements; } variable: values of the array. key: keys of the array.

What is the syntax of a foreach loop?

$_GET

What superglobal array stores data embedded in a query string?

Arguments

When a function is called, the ______________ are passed into the function.

default

When the value returned by a switch statement expression does not match a case label, the statements within the _________ label execute.

# single line comments /* * multiple line comments */ // single line comments

Which of the following ARE a correct syntax for creating PHP comments?

++$count $count += 1 $count = $count + 1

Which of the following ARE correct ways to add 1 to the $count variable?

10 === "10"

Which of the following answers does NOT return the boolean value TRUE?

d) All of the above

Which of the following can be used as the file extension of an external library file? a) php b) lib c) inc d) All of the above

; single line comments

Which of the following is NOT a correct syntax for creating PHP comments?

$count = 1

Which of the following is NOT a correct way to add 1 to the $count variable?

a) request

Which of the following is NOT a valid PHP command to include an external file? a) request b) require_once c) include d) include_once

byte

Which of the following is NOT a valid PHP data type?

d) If I want to have a variable to be accessible anywhere in any script in my PHP application, I should create a superglobal variable.

Which of the following is NOT true regarding a superglobal variable in PHP? a) Superglobals are pre-defined in PHP code library. They can be used in my code without first defining them. b) A superglobal can be accessed anywhere in any PHP file. c) The name of any superglobal in PHP always starts with an underscore (_). d) If I want to have a variable to be accessible anywhere in any script in my PHP application, I should create a superglobal variable.

$salesorder

Which of the following is syntactically correct in declaring a valid PHP variable?

define("SALE_TAX", 0.70);

Which of the following is the correct PHP code that defines a new constant named "SALE_TAX"?

c) filter_input

Which of the following is the correct filter function to use to filter data from a form? a) filter_var b) filter_has_var c) filter_input d) filter_form

a) SWITCH statement

Which of the following structures cannot be used to repeatedly execute a block of PHP statements? a) SWITCH statement b) WHILE structure c) FOR structure d) DO ... WHILE structure

Web server

XAMPP is an all-in-one package including a web server, an application server, a database server, and other tools. The "A" in "XAMPP" stands for "Apache", which is a(n) ______.

break

You can exit a switch statement using a(n) _______ statement.

counter

A(n) _____ is a variable that increments or decrements with each repetition of a loop statement.

Each element consists of a value and its associated key.

A PHP array is called an associative array. What does this mean?

d) All of the above

A PHP function may accept ____ parameter(s). a) 0 b) 1 c) 2 or more d) All of the above

-require_once -include_once

*_once versions guarantee that the file in question is included only once in each script file. What are the two types?

local

A variable defined inside a function is called a ______ variable.

-Languages that execute on client-side/local browsers. -The server is not involved in rendering the code

Client-side scripting and markup languages are what?

HTML, CSS, JavaScript

Client-side scripting and markup languages include:

TRUE

Comparison operators always return a Boolean value. (True/False)

IF...ELSE statement result: if (a==5) { a += 4; else { a += 7;

Convert this conditional expression into an if...else statement: a += (a==5) ? 4 : 7;

FALSE

Decision-making structures such as IF ... ELSE ... cannot be nested. (True/False)

"%" is a modulo (The remainder after division of one number by another) "++" increments a variable by 1. "--" decrements a variable by 1.

Define the differences between these operators: "%", "++", and "--"

"=" assigns a value to a variable or constant. (example: $a = 5;) "==" checks if two values equal one another (example: 5 == "5") "===" checks if two values are identical to one another (example: "10" === "10" would return true; "10" === 10 would return false)

Define the differences between these operators: "=", "==", and "==="

"include" displays a warning and then continues processing the script.

Define what "include" does when the file to be included is not found.

Equality: ==, only values concerned. Identity: ===, both values and types concerned.

List the equality and identity operators.

Inequality: != or <> Non-identity: !==

List the inequality and non-identity operators.

Dynamic

PHP arrays are ____________: array size is changeable at run-time.

Heterogeneous

PHP arrays are ____________________: values of different types can be stored in the same array.

The data type of a variable cannot be declared. The data type is automatically determined. The data type can change dynamically.

PHP is a weakly and dynamically typed language: define this.

weakly, dynamically

PHP is a(n) _______ typed programming language. (2 answers)

Languages that execute on the server. Web browser is not able to render the code.

Server-side scripting languages are what?

<?php ..... ?>

Standard PHP script delimiters: (what is the code?)

TRUE

Statements in a PHP function do not get executed until the function is called. (True/False)

square(10) OR square (10);

The PHP function square returns the square of a number. The function is defined as follows: function square($x) { return pow($x, 2); } The PHP code that calls/invokes the function to determine the square of 10 is what?

DO ... WHILE ...

The ____ structure tests a condition after executing a series of statement.

dot (.) Example: $msg_num = 5; echo "You have " . $msg_num . "messages.";

The ___________ operator combines/concatenates multiple strings into one.

explode( ) The syntax: explode(separator, string); Example: $email = "[email protected]"; $email_array = explode('@', $email); $username = $email_array[0]; // contains "ranchang"

The ______________ function splits a string into pieces on a specified separator and returns string pieces in an array.

submit

The button in an HTML form that sends data by default when it is clicked is called a ______ button.

array(key => value , .....) Key may only be an integer or string. Value may be any value of any type: primitive data, arrays, or objects. Example: Array ( [car] => Ferrari [number] => 21 [city] => Indianapolis )

What is the syntax for creating an array with the array() construct?

c) $SpeedingTickets = 0; $Age = 24;

The following PHP statement determines the risk factor of a client from his/her number of speeding tickets and age: ($SpeedingTickets >0 || $Age <= 21) ? "High" : "Low"; Following answers show combinations of number of speeding tickets and age; Which of these answers does NOT result in a "High" risk factor? a) $SpeedingTickets = 3; $Age = 19; b) $SpeedingTickets = 0; $Age = 19; c) $SpeedingTickets = 0; $Age = 24; d) $SpeedingTickets = 3; $Age = 24;

both operands return a value of true

The following is the general syntax for the && operator: operand1 && operand2; The expression returns true if _________.

Reverse

The implode( ) and join( ) functions __________ the effects of explode( ).

Number Example: strlen("46202"); // returns 5 $zipcode = "46202" strlen($zipcode); //returns 5

The strlen( ) function: returns the ____________ of characters in a string.

Whitespace

The trim( ) function removes ________________ from the beginning and the end of a string.

Client tier Processing tier (middle tier, business tier) Data storage tier

Three-tier (multi-tier) system consists of three distinct pieces. What are they?

$value % 3

To determine whether a value is divisible by 3, you may evaluate the remainder of the value divided by 3. Which of the following PHP code correctly returns the reminder of the value divided by 3? Assume $value contains the value you want to assess.

Two-tier and Three-tier architecture

Two most common architectures are what?

Server and a client (server: back-end) (client: front-end)

Two-tier system consists of a __________ and a ___________.

a) http://localhost/reg_confirm.php?fname=kevin&lname=smith

Using a querystring allows additional data to be sent via a URL. Which of the following is a correct syntax of a querystring? a) http://localhost/reg_confirm.php?fname=kevin&lname=smith b) http://localhost/reg_confirm.php?fname=kevin+lname=smith c) http://localhost/reg_confirm.php?fname=kevin?lname=smith d) http://localhost/reg_confirm.php$fname=kevin$lname=smith

action

What HTML form attribute specifies where to send form data?

<option> and <select>

What HTML tag do you use to create a selection list with multiple items in a form? (2 answers)

http://localhost

What URL do you use to display index.php at the root of a web site that is hosted by a local web server?

Validate Filters: 1) FILTER_VALIDATE_EMAIL 2) FILTER_VALIDATE_BOOLEAN 3) FILTER_VALIDATE_FLOAT 4) FILTER_VALIDATE_INT 5) FILTER_VALIDATE_URL Sanitize Filters: 1) FILTER_SANITIZE_EMAIL 2) FILTER_SANITIZE_STRING 3) FILTER_SANITIZE_NUMBER_FLOAT 4) FILTER_SANITIZE_SPECIAL_CHARS 5) FILTER_SANITIZE_URL

What are common validate and sanitize filters?

Variables enclosed in parentheses in the function definition

What are parameters?

Local (variables): can only be accessed inside a function. Global (variables): the entire program, can only be accessed outside a function. Superglobal (variables): anywhere; system defined.

What are the 3 types of variable scopes?

1) single quoted 2) double quoted 3) heredoc notation

What are the 3 ways to construct strings?

Validation and Sanitization

What are the main types of data filtering in PHP? (2 answers)

1) Functions that return a numeric position in a string. Positions are zero-based. (Searching) 2) Functions that return a character or substring. (Extracting)

What are the two types of functions for search and extraction?

-require -include Examples: include (library_file_path_and_name); require (library_file_path_and_name);

What are the two ways to include library files within your script?

-(int) : cast to integer -(bool) : cast to boolean -(float) : cast to float -(string) : cast to string -(array) : cast to array -(object) : cast to object Example: <?php $foo = 10; // $foo is an integer $bar = (boolean) $foo; // $bar is a boolean ?>

What are the types allowed in casting?

Variables are named placeholders in computer memory for storing values.

What are variables?

get

What form method allows HTML form data to be sent by appending them to the end of a URL?

A constant contains an unchangeable value.

What is a constant?

The page is dynamically generated after processing a request. - The page is generated dynamically by the application at run-time. - Page content and design are dynamically presented and reflect up-todate, accurate information. Server-side script is also used. A database management system (DBMS) is needed. (Examples: MySQL, Microsoft SQL, and Oracle.)

What is a dynamic web page?

The Web page is the same each time it's viewed. Web content and design: -are determined by the authors when the page is created; -are statically presented in users' browsers. To update a static page, HTML source must be changed. Only client-side scripting languages can be used Good for simple web pages.

What is a static web page?

Backward slash "\" followed by a character. Examples: echo "I\'m from Chicago.<br>"; echo "Nancy said \"Hello World!\" to the crowd.";

What is an escape sequence?

Can be customized by adding or removing the semi-colons in front of code lines. Modify it with caution. Default settings are suitable for development environment, but not for production server.

What is the PHP configuration file for? How do you modify it to enable or disable settings?

http://localhost/I210/Lab01/index.php (example)

What is the URL for the default homepage at the web root?

if ($MyVariable == 10) echo "Your variable is equal to 10.";

What is the correct PHP code to output "Your variable is equal to 10" if the value of the variable MyVariable equals to 10?

while ($i <= 5) { echo "$i"; $i++; }

What is the correct syntax for a while statement?

-In WHILE loops the code may never be executed. -In DO...WHILE loops the code is always executed once

What is the key difference between a WHILE loop and a DO...WHILE loop?

0

What is the output of the following echo statement? $is_on = false ; echo (int) $is_on;

13

What is the output of the following echo statement? $price = (int) "12.99"; echo $price + 1;

conditional expression ? expression1:expression2 (If the conditional expression evaluates to true, expression1 executes; otherwise expression2 executes.)

What is the syntax for a conditional operator?

Comparison

_____________ operators are useful for comparing two expressions, variables, or values.

Architecture

_______________ is the structure of software system which is divided into different perspectives.

They display strings or values of variables. echo can output one or more strings; print can output only one string. echo returns nothing; print returns 1.

echo v.s. print


Conjuntos de estudio relacionados

ServSafe Quiz 4 (The flow of food)

View Set

Manhattan Prep 1000 GRE Words: Usage

View Set