PHP    Foundation  Questions: Basics

Foundation Bundle 3

Questions: PHP Basics

A string is a sequence of characters that denotes literal text in a program.

Using a pair of single quotes ('') and a pair of double quotes ("").

We can't have escape sequences inside single-quoted strings besides \' (to denote ' characters) and \\ (to denote \ characters) — everything inside a single-quoted string is, more or less, parsed literally. In contrast, in double-quoted strings, we can have a wide variety of escape sequences and they also support interpolation.

Yes. It's perfectly valid to do so.

<?php

$str = 'Single-quoted strings in PHP
can span
multiple lines';
<?php

$str = "Double-quoted strings in PHP
can also span
multiple lines";

An esacpe sequence denotes a special character in a string. It begins with the backslash (\) symbol and is followed by a character to, as a whole, represent the special character. An example is \n, used to denote a newline character.

Here are some escape sequences: \n, \t, \r, \\, \', \".

A newline character.

An operator is basically a symbol or a keyword that performs an operation over one or more given values. An example is the arithmetic addition operator, denoted as +, that adds two numbers together.

String concatenation refers to joining together two strings into one single string.

The period (.) symbol.

Integers are whole numbers, i.e. numbers without a fractional part. Examples are 1, 2, 3, 1000, -5, -50, etc.

Floats, or floating-point numbers, are numbers with a fractional part. Examples include 1.0 (the fractional part is zero but there is one and so the number is a float), 2.45, 3.00000001, 1000.5, -5.111, -50.2478, etc.

Yes, this is true.

Here are all the the six arithmetic operators of PHP: addition (+), subtraction (-), multiplication (*), division (/), exponentiation (**) and modulo (%).

It means that when both the multiplication (*) and the addition (+) operators exist in an operation, without any parentheses (()), multiplication would be performed first. For example, in the expression 2 * 5 + 10, multiplication would happen first and then addition, giving the result 20 (instead of 30 if addition was done first).

By grouping it in a pair of parentheses (()).

There are multiple ways of defining a variable. For example:

  • A variable is a container for holding data.
  • A variable is a name in a program, referring to a location in memory where data is stored.

We begin with the $ symbol, followed by the name of the variable to create, followed by the = symbol, followed by the value to initialize the variable with.

It means that two variables with names having different cases are considered to be different. That is, $foo is different from $FOO, $Foo, $fOO, etc.

A semantic error is an error in the meaning of a program. The program might run to completion but not produce the correct output.

Standard input refers to the stream that is pointed to by the STDIN constant provided by PHP. Typically, standard input in a PHP CLI program is tied to input from the keyboard.

A function represents a block of code that is executed whenever the function is called.

fgets() is meant to read data from a given file.

A constant behaves more or less like a variable, except for that once assigned a value, it can't be changed and that it doesn't begin with the $ character.

STDIN is a constant that points to the standard input stream in PHP.

A prompt message, which is immediately followed by an input request, describes what is required to be input (and even gives a visual hint for this using characters such as > or :).

In the following code, the echo statement outputs a prompt message:

<?php

echo 'Enter your name> ';
$input = fgets(STDIN);

(int) string_value.

.

An expression is a unitary piece of code that resolves down to a single value. An expression can be composed of expressions itself.

A keyword is simply a word that has a special meaning associated with it. An example is echo. It doesn't represent a constant value in PHP; instead, it serves to output text to the standard output stream.

An expression statement is a statement that is merely an expression. If PHP expects a statement somewhere and we provide it with an expression, what we have now is an expression statement.

True. All expressions can act as statements.

False.

A syntax error is an error in the syntax of code.