Treehouse PHP into Flashcards
php needs a .php extension to operate and wont work in a html ext
true
a simple synatx error may cause the entire page not to load
t
how to include in php
include(‘includes/header.php);
php variables start with what
$
to specify where a form posts its data you can add what to the form element
action=”action-process.php”
this woulld then load that .php file after submitting giving you access to the vars
what does var_dump do in php
shows all accesible variables in an array
you can then access a variable from within it like such
var_dump($_POST);
$name = $_POST[“name”];
in a form element, what keyword specifies if its a post form
method=”post”
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
at the end of the submission php page use the function header(“Location: page-thanks.php”);
in php how can we check if the server is performing a get or a post or w/e
$_SERVER[“REQUEST_METHOD”]
where are get variables set in a url
?var&var2 etc
what is the PHP keyword to retrieve the get message
$_GET[“status”]
in php how to check is a variable is set
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 to create an array in php
array=(1,2,3);
in php echo a single array element
echo array[0];
in php how to find the number of elements in an array
count(array)
how to iterate each element in an array in php
foreach($array as $x){echo $x}
in php using foreach to create a list you only need one ‘li’ and closing tag
t
how to add an element to an existing array
$products[]=2;//you can specify the key inside the brackets if youd like, i.e. [103]=2;
in php how to access an element by key
$array[1]
in php how to create an associative array
$country= array(
“name”=>”USA”,
“population=>2000);
how to access element in first dimension of nested array
$arr[0][0]
how do you post html from inside php
you can echo html elements
how to write a foreach loop using both key and falue
foreach($product as $key => $value)
in php how to use a url ?var&var etc
$var=$_GET[“passedvarname”];