Treehouse PHP into Flashcards

1
Q

php needs a .php extension to operate and wont work in a html ext

A

true

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

a simple synatx error may cause the entire page not to load

A

t

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

how to include in php

A

include(‘includes/header.php);

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

php variables start with what

A

$

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

to specify where a form posts its data you can add what to the form element

A

action=”action-process.php”

this woulld then load that .php file after submitting giving you access to the vars

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

what does var_dump do in php

A

shows all accesible variables in an array

you can then access a variable from within it like such

var_dump($_POST);
$name = $_POST[“name”];

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

in a form element, what keyword specifies if its a post form

A

method=”post”

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

in php after submitting a form, a good practice is to redirect them to a different page than the submission complete .php fpage; how can we do this

A

at the end of the submission php page use the function header(“Location: page-thanks.php”);

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

in php how can we check if the server is performing a get or a post or w/e

A

$_SERVER[“REQUEST_METHOD”]

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

where are get variables set in a url

A

?var&var2 etc

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

what is the PHP keyword to retrieve the get message

A

$_GET[“status”]

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

in php how to check is a variable is set

A

isset (best used in an if statement to check if _getstatus is there, and then check if the value is equal to something using th and operator

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

how to create an array in php

A

array=(1,2,3);

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

in php echo a single array element

A

echo array[0];

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

in php how to find the number of elements in an array

A

count(array)

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

how to iterate each element in an array in php

A

foreach($array as $x){echo $x}

17
Q

in php using foreach to create a list you only need one ‘li’ and closing tag

A

t

18
Q

how to add an element to an existing array

A

$products[]=2;//you can specify the key inside the brackets if youd like, i.e. [103]=2;

19
Q

in php how to access an element by key

A

$array[1]

20
Q

in php how to create an associative array

A

$country= array(
“name”=>”USA”,
“population=>2000);

21
Q

how to access element in first dimension of nested array

A

$arr[0][0]

22
Q

how do you post html from inside php

A

you can echo html elements

23
Q

how to write a foreach loop using both key and falue

A

foreach($product as $key => $value)

24
Q

in php how to use a url ?var&var etc

A

$var=$_GET[“passedvarname”];