Podcast
Questions and Answers
What is the purpose of the if...else statement?
What is the purpose of the if...else statement?
What is the syntax for the if statement?
What is the syntax for the if statement?
What is the purpose of the switch statement?
What is the purpose of the switch statement?
What is the effect of the expression $a += 5?
What is the effect of the expression $a += 5?
Signup and view all the answers
What is the purpose of the if...else if....else statement?
What is the purpose of the if...else if....else statement?
Signup and view all the answers
In PHP, what is the purpose of the $ symbol in a variable name?
In PHP, what is the purpose of the $ symbol in a variable name?
Signup and view all the answers
What is the output of the following code: <?php $t=date("H"); if ($t < 20) { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
What is the output of the following code: <?php $t=date("H"); if ($t < 20) { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
Signup and view all the answers
What happens when you add a double to an integer in PHP?
What happens when you add a double to an integer in PHP?
Signup and view all the answers
What is the purpose of arithmetic operations in PHP?
What is the purpose of arithmetic operations in PHP?
Signup and view all the answers
What is the purpose of the is_double() function in PHP?
What is the purpose of the is_double() function in PHP?
Signup and view all the answers
What is the purpose of concatenation in PHP?
What is the purpose of concatenation in PHP?
Signup and view all the answers
What is the use of the \n escape sequence in PHP?
What is the use of the \n escape sequence in PHP?
Signup and view all the answers
In PHP, what happens when you try to use a string in an arithmetic expression?
In PHP, what happens when you try to use a string in an arithmetic expression?
Signup and view all the answers
What is the purpose of type casting in PHP?
What is the purpose of type casting in PHP?
Signup and view all the answers
What is the use of the is_array() function in PHP?
What is the use of the is_array() function in PHP?
Signup and view all the answers
What is the purpose of the \t escape sequence in PHP?
What is the purpose of the \t escape sequence in PHP?
Signup and view all the answers
What is the primary use of PHP in web development?
What is the primary use of PHP in web development?
Signup and view all the answers
How are PHP scripts executed?
How are PHP scripts executed?
Signup and view all the answers
What is the default file extension for PHP files?
What is the default file extension for PHP files?
Signup and view all the answers
What happens when a PHP script is accessed by a client's web browser?
What happens when a PHP script is accessed by a client's web browser?
Signup and view all the answers
How are string literals defined in PHP?
How are string literals defined in PHP?
Signup and view all the answers
What is the purpose of variable interpolation in PHP?
What is the purpose of variable interpolation in PHP?
Signup and view all the answers
What is the similarity between PHP and C/C++?
What is the similarity between PHP and C/C++?
Signup and view all the answers
What is the purpose of the reserved PHP tag?
What is the purpose of the reserved PHP tag?
Signup and view all the answers
Study Notes
Arithmetic Operations
- Subtraction:
$a - $b
- Multiplication:
$a * $b
- Division:
$a / $b
- Assignment operators:
$a += 5
(also works for*=
and/=
)
Concatenation
- Use a period to join strings into one
PHP Control Structures
- Control structures: allow us to control the flow of execution through a program or script
- Grouped into conditional (branching) structures (e.g. if/else) and repetition structures (e.g. while loops)
PHP Conditional Statements
- if statement: executes some code only if a specified condition is true
- if...else statement: executes some code if a condition is true and another code if the condition is false
- if...else if....else statement: selects one of several blocks of code to be executed
- switch statement: selects one of many blocks of code to be executed
The if Statement
- Syntax:
if (condition) { code to be executed if condition is true; }
- Example: output "Have a good day!" if the current time is less than 20
The if...else Statement
- Syntax:
if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }
- Example: output "Have a good day!" if the current time is less than 20, and "Have a good night!" otherwise
PHP Details
- Procedural language
- C-like syntax:
{ } ;
- Extensive Function Library
- Good Web-server integration
- Script embedded in HTML
- Easy access to form data and output of HTML pages
- Not fully object-oriented
PHP and HTML
- HTML-embedded
- PHP scripts are essentially HTML pages with the occasional section of PHP script
- PHP script is enclosed in the tag pair:
<?php ?>
Variables
- Creation of variables: variable names always start with
$
sign - Rest of the variable name can contain alphanumeric, underscore, and hyphen
- Example:
$name = “abc”;
,$age = 36;
- PHP is case sensitive
Escape Sequences in PHP
-
\n
- Insert a new line character -
\r
- Carriage return -
\t
- Horizontal tab -
\\
- Backslash -
\$
- Dollar -
\"
- Double quote
Changing Data Type
- Type casting process involves dynamically changing the type of data item
- If we add a double to an integer, the result will be a double even if we are storing it in the original integer variable
Type Checking
-
is_array(var)
- returns TRUE if the variable is an array -
is_double(var)
- returns TRUE if the variable is a double -
is_float(var)
- returns TRUE if the variable is a floating point number -
is_int(var)
- returns TRUE if the variable is an integer -
is_string(var)
- returns TRUE if the variable is a string -
is_object(var)
- returns TRUE if the variable is an object
What is PHP?
- "PHP: Hypertext Preprocessor"
- Open-source, server-side scripting language
- Used to generate dynamic web-pages
- PHP scripts reside between reserved PHP tags
- Interpreted language, scripts are parsed at run-time rather than compiled beforehand
- Executed on the server-side
- Source-code not visible by client
What Can PHP Do?
- Generate dynamic page content
- Create, open, read, write, delete, and close files on the server
- Collect form data
- Send and receive cookies
- Add, delete, modify data in your database
- Control user-access
- Encrypt data
What does PHP code look like?
- Structurally similar to C/C++
- Supports procedural and object-oriented paradigm (to some degree)
- All PHP statements end with a semi-colon
- Each PHP script must be enclosed in the reserved PHP tag
Comments in PHP
- Standard C, C++, and shell comment symbols
-
//
C++ and Java-style comment -
#
Shell-style comments
String Handling
- String literals (constants) enclosed in double quotes “ ” or single quotes ‘ ’
- Within “”, variables are replaced by their value: – called variable interpolation
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Learn about basic PHP operations and control structures, including arithmetic operations, concatenation, and conditional statements.