PHP Flashcards
(46 cards)
What is a PHP script?
a file composed of HTML tags and PHP code inserted between<?php and ?>tags
What is a PHP Engine?
It compiles the requested PHP script and executes the code
What is contained in the php.ini file?
Configuration settings for PHP files
How is an echo statement used by a PHP script?
It produces output that is sent to the browser via HTTP response.
What setting in php.ini files controls error message generation?
error_reporting
What setting in php.ini files determines if error messages are sent to the browser??
display_errors
What are the four types of error messages in PHP?
- Parse Error: Syntax error when code is compiled
- Fatal Error: Runtime Error that halts execution
- Warning: Runtime error that doesn’t halt execution
- Notice: Runtime message of possible logic error
How are variables declared in PHP?
By initializing the variable.
What are the three rules for naming variables in PHP?
- Names must start with a $ symbol
- Can be any combination of letters, digits, or underscores
- May not start with a digit following the $
What is the difference between variable names, and functions / keyword names in PHP?
Variables are case sensitive, functions and keywords are not
How are PHP Constants different to variables?
- Constants cannot be changed
- Constants do not use $ in the name
- They are usually CAPITALIZED
How are PHP constants defined?
With the define(name, value) function or the const keyword
What is ‘variable interpolation’?
When the PHP engine substitutes the value of a variable for the variable name inside of a double-quoted string
What is the difference between double quoted and Single quoted strings in PHP?
- Single quotation strings disable variable interpolation.
- The only escape sequences in single quotation strings are // and /’
What is the PHP String concatenation operator?
A period
How does PHP handle strings encountered in an arithmetic expression?
- The string converted into an int
- Strings with “E” or “e” are evaluated as scientific notation.
- A string with leading digits can be converted into a number, but PHP generates a warning.
- Attempting arithmetic with a string that has no leading digits causes a fatal error.
In addition to the standard compound assignment operators,what additional operators are present in PHP?
- %= Mod By
- .= Concatenation
What are the additional comparison operators in PHP vs Java?
- <> (inequality)
- === (identical: values and types must be the same)
- !== (Not Identical)
- <=> (Spaceship: acts as java equals() returning an int)
Does a PHP switch statement compare with == or ===?
==
What is a PHP array?
An ordered collection of key/value pairs.
Keys must be integers or strings, but values can be any datatype
What are the two types of PHP arrays?
- Indexed Array: Array with integer keys, similar to java array.
- Associative Array: String keys
What is the syntax of a foreach loop in PHP?
foreach($array as $value) {//body}
In a PHP associative array, what is the syntax for value assignment?
“key” => “value”
What are the 3 method pairs to sort PHP arrays?
- sort() / rsort(): sort indexed arrays in ascending / descending order
- asort() / arsort(): sort associative arrays based on values in ascending / descending order.
- ksort() / krsort(): sort associative arrays based on keys in ascending / descending order.