Podcast
Questions and Answers
What is the PHP style comment that is similar to C/C++ style comment?
What is the PHP style comment that is similar to C/C++ style comment?
What is the PHP comment that is similar to Unix Shell style comment?
What is the PHP comment that is similar to Unix Shell style comment?
What is the purpose of PHP if statement?
What is the purpose of PHP if statement?
What is the syntax of PHP if statement?
What is the syntax of PHP if statement?
Signup and view all the answers
What is the purpose of PHP if-else statement?
What is the purpose of PHP if-else statement?
Signup and view all the answers
What is the purpose of PHP switch statement?
What is the purpose of PHP switch statement?
Signup and view all the answers
What is the syntax of PHP switch statement?
What is the syntax of PHP switch statement?
Signup and view all the answers
What is the purpose of break statement in PHP switch statement?
What is the purpose of break statement in PHP switch statement?
Signup and view all the answers
What is the purpose of the default block in a PHP switch statement?
What is the purpose of the default block in a PHP switch statement?
Signup and view all the answers
What is the syntax of a PHP for loop?
What is the syntax of a PHP for loop?
Signup and view all the answers
When should we use a PHP while loop instead of a for loop?
When should we use a PHP while loop instead of a for loop?
Signup and view all the answers
What is the purpose of a PHP nested for loop?
What is the purpose of a PHP nested for loop?
Signup and view all the answers
How many times will the inner for loop be executed in a nested for loop if the outer loop is executed 3 times and the inner loop is executed 3 times?
How many times will the inner for loop be executed in a nested for loop if the outer loop is executed 3 times and the inner loop is executed 3 times?
Signup and view all the answers
What is the purpose of a PHP for each loop?
What is the purpose of a PHP for each loop?
Signup and view all the answers
What is the output of the PHP switch statement with a default block?
What is the output of the PHP switch statement with a default block?
Signup and view all the answers
What is the purpose of the initialization block in a PHP for loop?
What is the purpose of the initialization block in a PHP for loop?
Signup and view all the answers
How many ways can you define an associative array in PHP?
How many ways can you define an associative array in PHP?
Signup and view all the answers
What is the default representation of elements in a PHP indexed array?
What is the default representation of elements in a PHP indexed array?
Signup and view all the answers
What is the function used to count the length of a PHP indexed array?
What is the function used to count the length of a PHP indexed array?
Signup and view all the answers
How do you traverse a PHP indexed array?
How do you traverse a PHP indexed array?
Signup and view all the answers
What is the symbol used to associate a name/label with each array element in PHP?
What is the symbol used to associate a name/label with each array element in PHP?
Signup and view all the answers
What type of array can store numbers, strings or any object?
What type of array can store numbers, strings or any object?
Signup and view all the answers
What is another name for a PHP indexed array?
What is another name for a PHP indexed array?
Signup and view all the answers
What is the output of the count() function when used with an indexed array?
What is the output of the count() function when used with an indexed array?
Signup and view all the answers
What does the decoct() function convert a decimal number into?
What does the decoct() function convert a decimal number into?
Signup and view all the answers
What is the purpose of the base_convert() function?
What is the purpose of the base_convert() function?
Signup and view all the answers
What does the bindec() function convert into decimal?
What does the bindec() function convert into decimal?
Signup and view all the answers
What is the return type of the dechex() function?
What is the return type of the dechex() function?
Signup and view all the answers
What is the purpose of the dechex() function?
What is the purpose of the dechex() function?
Signup and view all the answers
What is the return type of the decoct() function?
What is the return type of the decoct() function?
Signup and view all the answers
What is the purpose of the bindec() function?
What is the purpose of the bindec() function?
Signup and view all the answers
What is the syntax of the base_convert() function?
What is the syntax of the base_convert() function?
Signup and view all the answers
What is one of the benefits of using PHP functions?
What is one of the benefits of using PHP functions?
Signup and view all the answers
How do you declare a user-defined function in PHP?
How do you declare a user-defined function in PHP?
Signup and view all the answers
What is the purpose of arguments in PHP functions?
What is the purpose of arguments in PHP functions?
Signup and view all the answers
What is the default passing method in PHP function arguments?
What is the default passing method in PHP function arguments?
Signup and view all the answers
What is the purpose of parameterized functions in PHP?
What is the purpose of parameterized functions in PHP?
Signup and view all the answers
What is the output of a parameterized function dependent on?
What is the output of a parameterized function dependent on?
Signup and view all the answers
What is the advantage of PHP functions in terms of code organization?
What is the advantage of PHP functions in terms of code organization?
Signup and view all the answers
What is the rule for naming a function in PHP?
What is the rule for naming a function in PHP?
Signup and view all the answers
Which PHP statement is used to print a string?
Which PHP statement is used to print a string?
Signup and view all the answers
What is the return type of the PHP print statement?
What is the return type of the PHP print statement?
Signup and view all the answers
What can be printed using the PHP echo statement?
What can be printed using the PHP echo statement?
Signup and view all the answers
What is the purpose of a variable in PHP?
What is the purpose of a variable in PHP?
Signup and view all the answers
What is similar between PHP echo and PHP print?
What is similar between PHP echo and PHP print?
Signup and view all the answers
What is the difference between PHP echo and PHP print?
What is the difference between PHP echo and PHP print?
Signup and view all the answers
Can PHP print be used to print arrays?
Can PHP print be used to print arrays?
Signup and view all the answers
What is the syntax of the PHP print statement?
What is the syntax of the PHP print statement?
Signup and view all the answers
How many primitive data types does PHP support?
How many primitive data types does PHP support?
Signup and view all the answers
What is the category of data type that includes arrays and objects?
What is the category of data type that includes arrays and objects?
Signup and view all the answers
What type of operator works on three operands?
What type of operator works on three operands?
Signup and view all the answers
What is the purpose of comments in PHP?
What is the purpose of comments in PHP?
Signup and view all the answers
How many categories of operators can PHP operators be categorized into based on operands?
How many categories of operators can PHP operators be categorized into based on operands?
Signup and view all the answers
What type of data type is a resource in PHP?
What type of data type is a resource in PHP?
Signup and view all the answers
How many scalar data types are there in PHP?
How many scalar data types are there in PHP?
Signup and view all the answers
What type of operator is the '+' symbol in the expression $num = 10 + 20?
What type of operator is the '+' symbol in the expression $num = 10 + 20?
Signup and view all the answers
What is the purpose of a PHP foreach loop?
What is the purpose of a PHP foreach loop?
Signup and view all the answers
What is the syntax of a PHP while loop?
What is the syntax of a PHP while loop?
Signup and view all the answers
What is a nested while loop in PHP?
What is a nested while loop in PHP?
Signup and view all the answers
What is the purpose of a PHP do-while loop?
What is the purpose of a PHP do-while loop?
Signup and view all the answers
What is the output of the example PHP while loop?
What is the output of the example PHP while loop?
Signup and view all the answers
How many times will the inner while loop be executed if the outer loop is executed 3 times and the inner loop is executed 3 times?
How many times will the inner while loop be executed if the outer loop is executed 3 times and the inner loop is executed 3 times?
Signup and view all the answers
What is the example output of a PHP foreach loop?
What is the example output of a PHP foreach loop?
Signup and view all the answers
What is the purpose of using a foreach loop in PHP?
What is the purpose of using a foreach loop in PHP?
Signup and view all the answers
What is the purpose of PHP array() function?
What is the purpose of PHP array() function?
Signup and view all the answers
What is the purpose of PHP array_change_key_case() function?
What is the purpose of PHP array_change_key_case() function?
Signup and view all the answers
What does PHP array_chunk() function do?
What does PHP array_chunk() function do?
Signup and view all the answers
What is the output of the given PHP code: array('sonoo' => 400000, 'john' => 500000, 'rahul' => 300000)?
What is the output of the given PHP code: array('sonoo' => 400000, 'john' => 500000, 'rahul' => 300000)?
Signup and view all the answers
What type of array is created by the PHP code: array(400000, 500000, 300000)?
What type of array is created by the PHP code: array(400000, 500000, 300000)?
Signup and view all the answers
What is the function used to count the length of a PHP array?
What is the function used to count the length of a PHP array?
Signup and view all the answers
How can you traverse a PHP indexed array?
How can you traverse a PHP indexed array?
Signup and view all the answers
What is the symbol used to associate a name/label with each array element in PHP?
What is the symbol used to associate a name/label with each array element in PHP?
Signup and view all the answers
What is the purpose of the default block in a PHP switch statement?
What is the purpose of the default block in a PHP switch statement?
Signup and view all the answers
What is the syntax of a PHP for loop?
What is the syntax of a PHP for loop?
Signup and view all the answers
What is the purpose of a PHP for each loop?
What is the purpose of a PHP for each loop?
Signup and view all the answers
What is the output of the PHP for loop example?
What is the output of the PHP for loop example?
Signup and view all the answers
What is the purpose of the initialization block in a PHP for loop?
What is the purpose of the initialization block in a PHP for loop?
Signup and view all the answers
What happens in a PHP nested for loop?
What happens in a PHP nested for loop?
Signup and view all the answers
What is the output of the PHP nested for loop example?
What is the output of the PHP nested for loop example?
Signup and view all the answers
When should a PHP while loop be used instead of a for loop?
When should a PHP while loop be used instead of a for loop?
Signup and view all the answers
What does PHP stand for?
What does PHP stand for?
Signup and view all the answers
What is the primary requirement for web development using PHP?
What is the primary requirement for web development using PHP?
Signup and view all the answers
What is the file extension used to save a PHP file?
What is the file extension used to save a PHP file?
Signup and view all the answers
Why is PHP is faster than other scripting languages?
Why is PHP is faster than other scripting languages?
Signup and view all the answers
What is the purpose of PHP in web development?
What is the purpose of PHP in web development?
Signup and view all the answers
What software stack is recommended to install PHP?
What software stack is recommended to install PHP?
Signup and view all the answers
What is the category of data type that includes arrays and objects?
What is the category of data type that includes arrays and objects?
Signup and view all the answers
What is the purpose of PHP in web development besides creating dynamic websites?
What is the purpose of PHP in web development besides creating dynamic websites?
Signup and view all the answers
What is the main difference between PHP echo and PHP print?
What is the main difference between PHP echo and PHP print?
Signup and view all the answers
What is the purpose of a variable in PHP?
What is the purpose of a variable in PHP?
Signup and view all the answers
What can be printed using the PHP print statement?
What can be printed using the PHP print statement?
Signup and view all the answers
What is the return type of the PHP print statement?
What is the return type of the PHP print statement?
Signup and view all the answers
Why are PHP functions beneficial in terms of code organization?
Why are PHP functions beneficial in terms of code organization?
Signup and view all the answers
What is similar between PHP echo and PHP print?
What is similar between PHP echo and PHP print?
Signup and view all the answers
What is the syntax of the PHP print statement?
What is the syntax of the PHP print statement?
Signup and view all the answers
Can PHP print be used to print arrays?
Can PHP print be used to print arrays?
Signup and view all the answers
What is the return type of the strlen function?
What is the return type of the strlen function?
Signup and view all the answers
What does the abs function return for a floating-point value?
What does the abs function return for a floating-point value?
Signup and view all the answers
What is the purpose of the ceil function?
What is the purpose of the ceil function?
Signup and view all the answers
What is the return type of the sqrt function?
What is the return type of the sqrt function?
Signup and view all the answers
What does the decbin function convert a decimal number into?
What does the decbin function convert a decimal number into?
Signup and view all the answers
What is the purpose of the floor function?
What is the purpose of the floor function?
Signup and view all the answers
What is the return type of the dechex function?
What is the return type of the dechex function?
Signup and view all the answers
What is the purpose of the sqrt function?
What is the purpose of the sqrt function?
Signup and view all the answers
What does the PHP strtolower()
function do?
What does the PHP strtolower()
function do?
Signup and view all the answers
What is the primary difference between a do-while loop and a while loop in PHP?
What is the primary difference between a do-while loop and a while loop in PHP?
Signup and view all the answers
What is the output of the ucfirst()
function with the input 'my name is anuj'?
What is the output of the ucfirst()
function with the input 'my name is anuj'?
Signup and view all the answers
What does the PHP strrev()
function do?
What does the PHP strrev()
function do?
Signup and view all the answers
What is the purpose of the PHP break statement?
What is the purpose of the PHP break statement?
Signup and view all the answers
What is the purpose of the PHP strlen()
function?
What is the purpose of the PHP strlen()
function?
Signup and view all the answers
What is an advantage of using PHP functions?
What is an advantage of using PHP functions?
Signup and view all the answers
What is the purpose of a PHP function?
What is the purpose of a PHP function?
Signup and view all the answers
What does the PHP lcfirst()
function do?
What does the PHP lcfirst()
function do?
Signup and view all the answers
What is the purpose of the PHP ucwords()
function?
What is the purpose of the PHP ucwords()
function?
Signup and view all the answers
What is the format of a PHP do-while loop?
What is the format of a PHP do-while loop?
Signup and view all the answers
What is the output of the strtoupper()
function with the input 'my name is anuj'?
What is the output of the strtoupper()
function with the input 'my name is anuj'?
Signup and view all the answers
What happens when the PHP break statement is used inside a nested loop?
What happens when the PHP break statement is used inside a nested loop?
Signup and view all the answers
What is the characteristic of a PHP function that allows it to be reused?
What is the characteristic of a PHP function that allows it to be reused?
Signup and view all the answers
What does the PHP strtolower()
function return?
What does the PHP strtolower()
function return?
Signup and view all the answers
What is the benefit of using PHP functions in terms of code organization?
What is the benefit of using PHP functions in terms of code organization?
Signup and view all the answers
How many primitive data types does PHP support?
How many primitive data types does PHP support?
Signup and view all the answers
What are the categories of PHP data types?
What are the categories of PHP data types?
Signup and view all the answers
What type of operator works on three operands?
What type of operator works on three operands?
Signup and view all the answers
What is the purpose of PHP comments?
What is the purpose of PHP comments?
Signup and view all the answers
How many types of comments does PHP support?
How many types of comments does PHP support?
Signup and view all the answers
What is the category of data type that includes resource and NULL?
What is the category of data type that includes resource and NULL?
Signup and view all the answers
What type of operator works on single operands?
What type of operator works on single operands?
Signup and view all the answers
How many categories of operators are there in PHP based on the number of operands?
How many categories of operators are there in PHP based on the number of operands?
Signup and view all the answers
What is the purpose of PHP multidimensional array?
What is the purpose of PHP multidimensional array?
Signup and view all the answers
How many ways can you define an associative array in PHP?
How many ways can you define an associative array in PHP?
Signup and view all the answers
What is the symbol used to associate a name/label with each array element in PHP?
What is the symbol used to associate a name/label with each array element in PHP?
Signup and view all the answers
What is another name for a PHP indexed array?
What is another name for a PHP indexed array?
Signup and view all the answers
What is the purpose of an associative array in PHP?
What is the purpose of an associative array in PHP?
Signup and view all the answers
What is represented by a PHP multidimensional array?
What is represented by a PHP multidimensional array?
Signup and view all the answers
In which form is a PHP multidimensional array represented?
In which form is a PHP multidimensional array represented?
Signup and view all the answers
What type of array can store numbers, strings, or any object in PHP?
What type of array can store numbers, strings, or any object in PHP?
Signup and view all the answers
Which of the following PHP comments is similar to Unix Shell style comment?
Which of the following PHP comments is similar to Unix Shell style comment?
Signup and view all the answers
What is the purpose of the PHP if-else statement?
What is the purpose of the PHP if-else statement?
Signup and view all the answers
What is the purpose of the PHP switch statement?
What is the purpose of the PHP switch statement?
Signup and view all the answers
What is the syntax of the PHP if statement?
What is the syntax of the PHP if statement?
Signup and view all the answers
What is the purpose of the break statement in PHP switch statement?
What is the purpose of the break statement in PHP switch statement?
Signup and view all the answers
What is the syntax of the PHP if-else statement?
What is the syntax of the PHP if-else statement?
Signup and view all the answers
What is the purpose of the PHP multi-line comments?
What is the purpose of the PHP multi-line comments?
Signup and view all the answers
What is the output of the PHP if statement if the condition is true?
What is the output of the PHP if statement if the condition is true?
Signup and view all the answers
What is the return type of the PHP abs() function?
What is the return type of the PHP abs() function?
Signup and view all the answers
What does the PHP ceil() function do?
What does the PHP ceil() function do?
Signup and view all the answers
What is the purpose of the PHP decbin() function?
What is the purpose of the PHP decbin() function?
Signup and view all the answers
What is the return type of the PHP sqrt() function?
What is the return type of the PHP sqrt() function?
Signup and view all the answers
What does the PHP floor() function do?
What does the PHP floor() function do?
Signup and view all the answers
What is the purpose of the PHP strlen() function?
What is the purpose of the PHP strlen() function?
Signup and view all the answers
What is the return type of the PHP dechex() function?
What is the return type of the PHP dechex() function?
Signup and view all the answers
What does the PHP sqrt() function return?
What does the PHP sqrt() function return?
Signup and view all the answers
What is the advantage of using POST request over GET request?
What is the advantage of using POST request over GET request?
Signup and view all the answers
What is the purpose of PHP include and require constructs?
What is the purpose of PHP include and require constructs?
Signup and view all the answers
What is the difference between PHP include and require?
What is the difference between PHP include and require?
Signup and view all the answers
What is the purpose of a PHP file extension .html?
What is the purpose of a PHP file extension .html?
Signup and view all the answers
What is the output of the PHP script if a required file is missing?
What is the output of the PHP script if a required file is missing?
Signup and view all the answers
What is the benefit of using PHP include and require constructs?
What is the benefit of using PHP include and require constructs?
Signup and view all the answers
What type of file can be included using PHP include and require constructs?
What type of file can be included using PHP include and require constructs?
Signup and view all the answers
What is the purpose of including a file in a PHP script?
What is the purpose of including a file in a PHP script?
Signup and view all the answers
Study Notes
PHP Comments
- There are two ways to use single line comments in PHP:
//
(C++ style) and#
(Unix Shell style) - PHP also supports multi-line comments, which are enclosed within
/*
and*/
PHP Control Statements
- PHP if-else statement is used to test a condition and execute different blocks of code based on the condition
- There are various ways to use if statements in PHP:
if
,if-else
,if-else-if
, andnested if
- The syntax for an
if
statement isif (condition) { code to be executed }
- The syntax for an
if-else
statement isif (condition) { code to be executed if true } else { code to be executed if false }
- PHP also has a
switch
statement, which is used to execute one statement from multiple conditions - The syntax for a
switch
statement isswitch (expression) { case value1: code to be executed; break; ... default: code to be executed if all cases are not matched; }
PHP Loops
- PHP has several types of loops:
for
,foreach
, andwhile
- The
for
loop is used to execute a block of code for a specified number of times - The syntax for a
for
loop isfor (initialization; condition; increment/decrement) { code to be executed }
- PHP also supports nested
for
loops - The
foreach
loop is used to traverse array elements - PHP has a
foreach
loop for arrays, which is used to traverse array elements
PHP Functions
- PHP allows you to declare and call user-defined functions easily
- The syntax for declaring a user-defined function is
function functionname() { code to be executed }
- PHP functions support arguments, which are passed to the function when it is called
- PHP supports call by value, call by reference, default argument values, and variable-length argument lists
- PHP parameterized functions are functions with parameters
PHP Arrays
- PHP has two types of arrays: indexed arrays and associative arrays
- Indexed arrays are represented by an index number, which starts from 0
- Indexed arrays can store numbers, strings, or any object
- Associative arrays are represented by a key-value pair
- PHP provides the
count()
function, which returns the length of an array - You can easily traverse an array in PHP using a
foreach
loop
PHP Math Functions
- PHP has several math functions, including
dechex()
,decoct()
,base_convert()
, andbindec()
- The
dechex()
function converts a decimal number to a hexadecimal number - The
decoct()
function converts a decimal number to an octal number - The
base_convert()
function converts a number from one base to another - The
bindec()
function converts a binary number to a decimal number
PHP Echo
- Prints a string
- Can print multi-line strings
- Escapes characters
- Can print variable values
PHP Print
- Similar to PHP echo
- Always returns 1
- Syntax:
int print(string $arg)
- Can print strings, multi-line strings, escaping characters, and variables
PHP Variables
- A variable is a name of a memory location that holds data
- Supports 8 primitive data types:
- Scalar Types: boolean, integer, float, string
- Compound Types: array, object
- Special Types: resource, NULL
PHP Data Types
- Scalar Types:
- boolean
- integer
- float
- string
- Compound Types:
- array
- object
- Special Types:
- resource
- NULL
PHP Operators
- Can be categorized into:
- Arithmetic Operators
- Comparison Operators
- Bitwise Operators
- Logical Operators
- String Operators
- Incrementing/Decrementing Operators
- Array Operators
- Type Operators
- Execution Operators
- Error Control Operators
- Assignment Operators
- Can also be categorized into:
- Unary Operators (works on single operands)
- Binary Operators (works on two operands)
- Ternary Operators (works on three operands)
PHP Comments
- Used to describe code
- Can be single-line or multi-line
- Helps other developers understand the code
PHP Switch
- Used for decision-making
- Syntax:
switch (expression) { case value: code; break; ... default: code; }
PHP Loops
- PHP For Loop:
- Used to traverse a set of code for a specified number of times
- Syntax:
for (initialization; condition; increment/decrement) { code to be executed }
- PHP Nested For Loop:
- Used for inner or nested for loops
- Inner for loop is executed fully for one outer for loop
- PHP For Each Loop:
- Used to traverse array elements
- Syntax:
foreach ($array as $var) { code to be executed }
- PHP While Loop:
- Used to traverse a set of code
- Syntax:
while (condition) { code to be executed }
- PHP Nested While Loop:
- Used for inner or nested while loops
- Inner while loop is executed fully for one outer while loop
- PHP Do While Loop:
- Used to traverse a set of code like while loop
- Syntax:
do { code to be executed } while (condition)
PHP Array Functions
- PHP array() function:
- Creates and returns an array
- Allows creation of indexed, associative, and multidimensional arrays
- PHP array_change_key_case() function:
- Changes the case of all keys in an array
- Syntax:
array array_change_key_case ( array $array [, int $case = CASE_LOWER ] )
- PHP array_chunk() function:
- Splits an array into chunks
- Divides an array into many parts
Introduction to PHP
- PHP stands for HyperText Preprocessor
- It's an interpreted language, no compilation is needed
- PHP is a server-side scripting language
- PHP is faster than other scripting languages like ASP and JSP
PHP Examples
- PHP files must be saved with a
.php
extension - A simple PHP example is shown with a
hello.php
file - Output of the example: "Hello by PHP"
Web Development
- PHP is widely used in web development
- Dynamic websites can be developed using PHP
- Basic knowledge of HTML, CSS, JavaScript, AJAX, XML, and JSON is required for web development
PHP Echo
-
echo
is a language construct in PHP - It's used to print strings, multi-line strings, escaping characters, and variable values
- Examples of
echo
usage are shown inecho1.php
,echo2.php
, andecho3.php
files - Output of examples: "Hello by PHP echo", "Hello by PHP echo this is multi line text printed by PHP echo statement", and "Hello escape "sequence" characters"
PHP Print
-
print
is a language construct in PHP - It's used to print strings, multi-line strings, escaping characters, and variable values
- Unlike
echo
,print
always returns 1 - Examples of
print
usage are shown inprint1.php
,print2.php
, andprint3.php
files - Output of examples: "Hello by PHP print Hello by PHP print()", "Hello by PHP print this is multi line text printed by PHP print statement", and "Hello escape "sequence" characters by PHP print"
PHP Variables
- A variable in PHP is a name of memory location that holds data
- PHP do-while loop is guaranteed to run at least once
- Syntax of PHP do-while loop:
do { //code to be executed } while (condition);
PHP Break
- The
break
statement breaks the execution of current for, while, do-while, switch, and for-each loop - If used inside an inner loop, it breaks the execution of the inner loop only
- Syntax of PHP
break
:jump statement; break;
PHP Functions
- A PHP function is a piece of code that can be reused many times
- It can take input as an argument list and return a value
- There are thousands of built-in functions in PHP
- Advantages of PHP functions: code reusability
- Examples of PHP functions:
strtolower()
,strtoupper()
,ucfirst()
,lcfirst()
,ucwords()
, andstrrev()
PHP String Functions
-
strtolower()
function returns a string in lowercase letters -
strtoupper()
function returns a string in uppercase letters -
ucfirst()
function returns a string converting the first character into uppercase -
lcfirst()
function returns a string converting the first character into lowercase -
ucwords()
function returns a string converting the first character of each word into uppercase -
strrev()
function returns a reversed string
PHP Math
- PHP provides many predefined math constants and functions
- Math functions:
abs()
,ceil()
,floor()
,sqrt()
,decbin()
, anddechex()
-
abs()
function returns the absolute value of a given number -
ceil()
function rounds fractions up -
floor()
function rounds fractions down -
sqrt()
function returns the square root of a given argument -
decbin()
function converts a decimal number into binary -
dechex()
function converts a decimal number into hexadecimal
PHP Data Types
- PHP supports 8 primitive data types, categorized into 3 types: Scalar, Compound, and Special.
- Scalar types: 4 types - boolean, integer, float, and string.
- Compound types: 2 types - array and object.
- Special types: 2 types - resource and NULL.
PHP Operators
- PHP operators are symbols used to perform operations on operands.
- Categorized into 10 forms: Arithmetic, Comparison, Bitwise, Logical, String, Incrementing/Decrementing, Array, Type, Execution, and Error Control.
- Operators can also be categorized into 3 forms based on the number of operands: Unary, Binary, and Ternary.
PHP Comments
- PHP comments are used to describe code or hide code.
- Supports single line and multi-line comments.
- Single line comments: 2 ways to use -
//
(C++ style) and#
(Unix Shell style). - Multi-line comments: enclose all lines within
/* */
.
PHP Control Statements
- PHP if-else statement: used to test conditions, with various forms - if, if-else, if-else-if, and nested if.
- PHP switch statement: used to execute one statement from multiple conditions, similar to if-else-if statement.
PHP Arrays
- Associative array: a type of array that uses strings as keys.
- Two ways to define associative array: using the
array()
function or by assigning each key-value pair separately. - PHP Multidimensional array: an array of arrays, used to store tabular data.
PHP Math
- PHP provides many predefined math constants and functions.
- Math functions:
abs()
,ceil()
,floor()
,sqrt()
,decbin()
, anddechex()
.
PHP Include File
- PHP allows you to include files to reuse page content.
- Two ways to include files:
include
andrequire
. - Advantage: code reusability.
-
include
vsrequire
:include
allows the script to continue if the file is missing, whilerequire
halts the script with a fatal error.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Learn about PHP comments and control statements, including single-line and multi-line comments, if-else statements, and more.