PHP Flashcards

1
Q

PHP is a _________

A

server scripting language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

PHP is an acronym for ________

A

“PHP: Hypertext Preprocessor”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

PHP code is executed on the _____, and the result is returned to the browser as plain HTML

A

server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

PHP can generate _______ page content.
PHP can collect _______
PHP can send and receive _____
PHP can ____ data

A

dynamic
form data
cookies
encrypt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

PHP can add, delete, _____ data in your database.
PHP can ____, open, read, write, ____, and close files on the server

A

modify
create, delete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

To check your php version you can use the ________ function:

A

phpversion()
echo phpversion();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A PHP script starts with ____ and ends with ?>

A

<?php

<?php
// PHP code goes here
?>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

PHP statements end with a _________

A

semicolon (;)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

All variable names are ________

A

case-sensitive!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Comments
Single line: // or ____
Multiline comment: _____

A

#
/* This is a multi-line comment */

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In PHP, a variable starts with the ___ sign, followed by the name of the variable:

A

$
$x = 5;
$y = “John”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

To get the data type of a variable, use the ________ function.

A

var_dump()
$x = 5;
var_dump($x);

int(5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A variable declared ______ a function has a GLOBAL SCOPE and can only be accessed outside a function:

A

outside

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A variable declared _____ a function has a LOCAL SCOPE and can only be accessed within that function:

A

within

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

With PHP, there are two basic ways to get output: ____ and _____.

A

echo and print

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

echo “Hello world!”;
_____ “Hello world!”;

A

print “Hello world!”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The var_dump() function returns the ________ and the _______

A

data type , value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

$x = 59;
var_dump($x);

A

int(59)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The PHP _____ function returns the length of a string.

A

strlen()
echo strlen(“Hello world!”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

The PHP ___________function counts the number of words in a string.

A

str_word_count()
echo str_word_count(“Hello world!”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

he PHP _______ function searches for a specific text within a string.

A

strpos()
echo strpos(“Hello world!”, “world”);

output: 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

The _______ function returns the string in upper case:

A

strtoupper()
echo strtoupper($x);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

The ________ function returns the string in lower case:

A

strtolower()
echo strtolower($x);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

The PHP _______ function replaces some characters with some other characters in a string.

A

str_replace()
$x = “Hello World!”;
echo str_replace(“World”, “Dolly”, $x);

Output: Hello Dolly!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

The PHP ______ function reverses a string.

A

strrev()
echo strrev($x);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

The ______ removes any whitespace from the beginning or the end:

A

trim()
echo trim($x);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

The PHP _____ function splits a string into an array.

The first parameter of the explode() function represents the “______”. The “_______” specifies where to split the string.

A

explode()
separator, separator

$x = “Hello World!”;
$y = explode(“ “, $x);
print_r($y);

Array ( [0] => Hello [1] => World!)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

To concatenate, or combine, two strings you can use the______operator:

A

.

$x = “Hello”;
$y = “World”;
$z = $x . $y;
echo $z;
HelloWorld

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

Slicing string has _______ function.

A

substr() function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Start the slice at index 6 and end the slice 5 positions later:

A

$x = “Hello World!”;
echo substr($x, 6, 5);
World

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

To insert characters that are illegal in a string, use an ________

A

escape character slash sign “

$x = “We are the so-called Slash sign”Vikings Slash sign” from the north.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

' _____Quote
" _____ Quote
$ ______
\n ____ Line

A

Single
Double
PHP variables ($ sign)
New

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

There are three main numeric types in PHP:
______, _______, ________

A

Integer, Float, Number Strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

In addition, PHP has two more data types used for numbers:

______
NaN

A

Infinity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

NaN stands for ______

A

Not a Number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

The _____ function returns the absolute (positive) value of a number:

A

abs() echo(abs(-6.7)); = 6.7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

The ____ function returns the square root of a number:

A

sqrt()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

The _____ function rounds a floating-point number to its nearest integer:

A

round()
echo(round(0.60));
1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

The _____ function generates a random number:

if you want a random integer between 10 and 100 (inclusive), use ________

A

rand()

echo(rand(10, 100));

echo(rand());
321343433 - 9 numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

To change a variable from one data type into another is called ______.

A

casting
Casting in PHP is done with these statements:

(string) - Converts to data type String
(int) - Converts to data type Integer
(float) - Converts to data type Float
(bool) - Converts to data type Boolean
(array) - Converts to data type Array
(object) - Converts to data type Object
(unset) - Converts to data type NULL

41
Q

$a = 5; // Integer
$b = 5.34; // float

$a = (string) $a;
$b = (string) $b;

//To verify the type of any object in PHP, use the var_dump() function:

var_dump($a);
var_dump($b);

Output: ?

A

Output:
string(1) “5”
string(4) “5.34”

42
Q

_____ are like variables, except that once they are defined they cannot be changed or undefined.

A

Constants

43
Q

To create a constant, use the _______ function.

A

define()

snytax:
define(name, value, case-insensitive);

44
Q

You can also create a constant by using the _____ keyword.

A

const
const MYCAR = “Volvo”;
echo MYCAR;

45
Q
A
46
Q

Create a constant with a case-sensitive name:

Create a constant with a case-insensitive name:

A

define(“GREETING”, “Welcome to W3Schools.com!”);
echo GREETING;

define(“GREETING”, “Welcome to W3Schools.com!”, true);
echo greeting;

47
Q

PHP has nine predefined constants that change value depending on where they are used, and therefor they are called “__________”.

A

magic constants

48
Q

These magic constants are written with a ____________ at the start and the end, except for the ClassName::class constant.

A

double underscore
__CLASS__

49
Q

__CLASS__
__DIR__
__FILE__
__FUNCTION__
__LINE__
__METHOD__
__NAMESPACE__
__TRAIT__
ClassName::class Returns the name of the specified class and the name of the namespace, if any.

A

class name is returned.
The directory of the file.
The file name including the full path.
function name is returned.
The current line number.
If used inside a function that belongs to a class, both class and function name is returned.
name of the namespace is returned.
If used inside a trait, the trait name is returned.

50
Q

and/ &&/ And -______
Or || - ________
xor / XOR - _______

A

True if both $x and $y are true
True if either $x or $y is true
True if either $x or $y is true, but not both

51
Q

!= and <> is _____
? :
$x = expr1 ? expr2 : expr3

A

Inequality
Ternary

52
Q

if statement - _______
if…else statement - ________
if…elseif…else statement - ________
switch statement - ______

A
  1. executes some code if one condition is true
  2. executes some code if a condition is true and another code if that condition is false
  3. executes different codes for more than two conditions
  4. selects one of many blocks of code to be executed
53
Q

switch (_____) {
_____ label1:
//code block
break;
case label2:
//code block;
break;

______:
//code block

A

expression
case
default

54
Q

The ____ loop - Loops through a block of code as long as the specified condition is true.

A

while

55
Q

With the ______ statement we can stop the current iteration, and continue with the next:

A

continue

while ($i < 6) {
$i++;
if ($i == 3) continue;
echo $i;

output: 12456

56
Q

The ______ loop - Loops through a block of code ___, and then repeats the loop as long as the specified condition is true.

A

do…while
once

57
Q

In do while statement, the _____ statement we can stop the loop even if the condition is still true:

A

break

58
Q

The ____ loop - Loops through a block of code a specified number of times.

A

for

for (expression1, expression2, expression3) {
// code block
}
expression1 is evaluated once
expression2 is evaluated before each iteration
expression3 is evaluated after each iteration

59
Q

The _____ loop - Loops through a block of code for each element in an array or each property in an object.

A

foreach

60
Q

The ______ statement can be used to jump out of different kind of loops.

A

break

61
Q

The ________ statement can be used to jump out of the current iteration of a loop, and continue with the next.

A

continue

62
Q

The real power of PHP comes from its ________.

A

functions

PHP has more than 1000 built-in functions, and in addition you can create your own custom functions.

63
Q

A function is a block of statements that can be used ________ in a program.

A

repeatedly

64
Q

A user-defined function declaration starts with the keyword _______, followed by the name of the function:

A

function

function myMessage() {
echo “Hello world!”;
}

65
Q

A function name must start with a letter or an ________. Function names are NOT case-sensitive.

A

underscore

66
Q

To call the function, just write its name followed by __________

A

parentheses ():

function myMessage() {
echo “Hello world!”;
}

myMessage();

67
Q

Information can be passed to functions through _________.

_____ are specified after the function name, inside the parentheses. You can add as many ______ as you want, just separate them with a comma.

A

arguments
Arguments
arguments

68
Q

To turn a function argument into a reference, the ___ operator is used:

A

&
function add_five(&$value)

69
Q

By using the _____ in front of the function parameter, the function accepts an ______ number of arguments. This is also called a ____ function.

A

… operator

unknown

variadic

70
Q

An ______ stores multiple values in one single variable

A

array

71
Q

An array is a ______ variable that can hold many values under a single name, and you can access the values by referring to an _______ number or name.

A

special

index

72
Q

In ______ arrays each item has an index number.

A

indexed

By default, the first item has index 0, the second item has item 1, etc.

73
Q

________ arrays are arrays that use named keys that you assign to them.

A

Associative

74
Q

You can _______ arrays by using the array() function:

$cars = ___(“Volvo”, “BMW”, “Toyota”);

A

create
array

Shorter syntax
$cars = [“Volvo”, “BMW”, “Toyota”];

75
Q

To access an array item you can refer to the ____ number.

A

index

$cars = array(“Volvo”, “BMW”, “Toyota”);
echo $cars[0];

76
Q

To change the value of an array item, use the ____ number:

A

index

$cars = array(“Volvo”, “BMW”, “Toyota”);
$cars[1] = “Ford”;
var_dump($cars);

77
Q

To loop through and print all the values of an indexed array, you could use a _____ loop, like this:

A

foreach

$cars = array(“Volvo”, “BMW”, “Toyota”);
foreach ($cars as $x) {
echo “$x <br></br>”;
}

78
Q

To access items from an _____ array, use the key name:

A

associative

$cars = array(“model” => “Mustang”, “year” => 1964);
echo $cars[“year”];

79
Q

To execute function, use the index number followed by parentheses ():

A

$myArr = array(“Volvo”, 15, myFunction);

$myArr2;

80
Q

To update an existing array item, you can refer to the ______ number for indexed arrays, and the _____ for associative arrays.

A

index $cars[1] = “Ford”;
key name $cars[“year”] = 2024;

81
Q

To add items to an existing array, you can use the _______ syntax.

A

bracket [ ]

$fruits = array(“Apple”, “Banana”, “Cherry”);
$fruits[] = “Orange”;

82
Q

To add multiple items to an existing array, use the _______ function.

A

array_push()

$fruits = array(“Apple”, “Banana”, “Cherry”);
array_push($fruits, “Orange”, “Kiwi”, “Lemon”);

83
Q

To add multiple items to an Associative array, you can use the ____ operator.

A

+=

$cars = array(“brand” => “Ford”, “model” => “Mustang”);
$cars += [“color” => “red”, “year” => 1964];

84
Q

To remove an existing item from an array, you can use the _______ function.

A

array_splice()

With the array_splice() function you specify the index (where to start) and how many items you want to delete.

$cars = array(“Volvo”, “BMW”, “Toyota”);
array_splice($cars, 1, 1);
BMW is removed

85
Q

You can also use the _______ function to delete existing array items.

A

unset()

unset($cars[1]);

Note: The unset() function does not re-arrange the indexes, meaning that after deletion the array will no longer contain the missing indexes.

86
Q

You can also use the ______function to remove items from an associative array.

A

array_diff()

$newarray = array_diff($cars, [“Mustang”, 1964]);

87
Q

The _________ function removes the last item of an array.

A

array_pop()

$cars = array(“Volvo”, “BMW”, “Toyota”);
array_pop($cars);

88
Q

The _______function removes the first item of an array.

A

array_shift()

89
Q

sort() - sort arrays in ________
asort() - sort _______ arrays in ascending order, according to the value
ksort() - sort associative arrays in ascending order, according to the ______

A

ascending order
associative
key

90
Q

rsort() - sort arrays in _______ order
arsort() - sort associative arrays in _______ order, according to the value
krsort() - sort associative arrays in descending order, according to the _______

A

descending
descending
key

91
Q

Some predefined variables in PHP are “________”, which means that they are always accessible, regardless of scope

A

superglobals

92
Q

The PHP superglobal variables are:

A

$GLOBALS
$_SERVER
$_REQUEST
$_POST
$_GET
$_FILES
$_ENV
$_COOKIE
$_SESSION

93
Q

$GLOBALS

A

An array that contains all global variables.

94
Q

$_SERVER

A

PHP super global variable which holds information about headers, paths, and script locations.

95
Q

$_REQUEST

A

PHP super global variable which contains submitted form data, and all cookie data.

an array containing data from $_GET, $_POST, and $_COOKIE.

96
Q

$_POST

A

contains an array of variables received via the HTTP POST method.

97
Q

$_GET

A

contains an array of variables received via the HTTP GET method.

98
Q

A regular expression is a sequence of characters that forms a __________

A

search pattern.