Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
28 Cards in this Set
- Front
- Back
What's the code for outputting 'Hello world'? |
<!DOCTYPE html> |
|
What are the 3 ways to comment? |
// single line comment
#single line comment
/* multi-line comment if you need one */ |
|
Case sensitivity: Which of the following are ok:
<?php |
Keywords aren't case-sensitive, so all would work. |
|
Case sensitivity: Which of the following would print:
<!DOCTYPE html>
|
Only the first one. Variables ARE case-sensitive. |
|
In PHP, a variable starts with ______, followed by the name of the variable |
a dollar sign: $
Examples: $name = "Abby"; $age = 5 |
|
How do you declare a variable in PHP? |
PHP has no command for declaring a variable. It is created the moment you first assign a value to it. |
|
Which of these follow the rules for PHP variables: 1. $text |
These are valid: 1. $text
These aren't valid variables: 2. @age <-- must start with letter or underscore |
|
Will this work:
<?php |
yes. outputs:
I love W3Schools.com! |
|
Rewrite this using concatenation:
<?php
|
<?php |
|
True or False:
|
True |
|
Talk about: PHP is a Loosely Typed Language |
We do not have to tell PHP which data type the variable is.
PHP automatically converts the variable to the correct data type, depending on its value.
|
|
What is scope of a variable?
|
The scope of a variable is the part of the script where the variable can be referenced/used. |
|
Name the php variable scopes. |
PHP has three different variable scopes: * local* global * static |
|
A variable declared outside a function has what kind of scope? |
global scope |
|
Where can a global scope variable be accessed? |
outside a function |
|
What's the scope of $x? <?php function myTest() { echo "<p>Variable x outside function is: $x</p>"; |
global (it's declared outside of the function) |
|
What will happen if we use $x inside the myTest() function as shown:
<?php function myTest() { echo "<p>Variable x outside function is: $x</p>"; |
Output:
Error: Notice: Undefined variable: x Variable x inside function is: Variable x outside function is: 5
Reason: x is declared outside of the function, so is not available in the function.
|
|
What will happen when we run this:
<?php
|
Output:
Variable x inside function is: 5
Variable x outside function is: |
|
The global keyword is used to...
|
...access a global variable from within a function. |
|
How do you access a global variable from within a function? |
Use the global keyword before the variables (inside the function):
<?php function myTest() { myTest(); |
|
PHP also stores all global variables in an array called... |
$GLOBALS[index] |
|
$GLOBALS[index]
The index holds... |
..the name of the variable. |
|
$GLOBALS[index]
True or False: This array is also accessible from within functions and can be used to update global variables directly. |
true |
|
Rewrite this using $GLOBALS[index]:
<?php function myTest() { myTest(); |
<?php function myTest() { myTest(); |
|
True or False:
Normally, when a function is completed/executed, all of its variables are deleted. |
True |
|
Sometimes we want a local variable NOT to be deleted. We need it for a further job. What can we do? |
use the static keyword when you first declare the variable
<?php myTest(); |
|
Static - What will the output be of:
<?php myTest();
Each time the function is called, that variable will still have the information it contained from the last time the function was called.
|
012 |
|
How could you get a line break at the end of each output of $x?
<?php myTest(); |
echo "<br />";
<?php echo "<br />"; myTest(); |