PHP Basics Flashcards

1
Q

Where are your project files located ion a xamp stack

A

htdocs

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

what do you do after each php command?

A

;

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

does whitespace matter in php?

A

No

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

what are other php tags formats?

A

<? ?>
<=? ?>

<% %>

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

how do you write a php comment

A

//same as javascript

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

What is this directive:
ini_set(display_errors, 0);

A

Stops the server from displaying errors.

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

What is this function:
phpinfo();

A

Tells you all of the data and configurations of your server.

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

what is php.ini

A

php copnfiguration file

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

What does this function do:
error_log(‘this is an error message’, 3, “filename.log’)

A

This creats a log file.

Creates a file for the error thrown and imputes the last value as well as naming the filoe the first value

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

How do you declare a variable in php

A

a $ before the variable name like this:
$name= “trent”;

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

Can you start a variable with a number in php?

A

No

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

how do you concontenat in php

A

you use the . symble like this:

Trent . ‘ ‘ . Lvingston

the above will oputput this:
Trent Livingston

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

what is pemdas in order of operations?

A

parenthisise exponents multiplication devision adition subtraction

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

how do you declare an array in php?

A

you set a variable and wrap the value in brackets or you use the old way

$arrayName = [asdff,adfadf,adfafd,dasfadsf]

Old way = $arrayName = array(265,26544,225,14585,’1232132’,kjhdfkh)

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

What is an associative array?

A

this is simalur to json as it is an array with a custom key and value pair. here is how you do this:

$names = [“first_name” => ‘Edwin’, “Last_Name” => ‘Diaz’ ];

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

what is PHP Constants

A

A constant is an identifier (name) for a simple value. The value cannot be changed during the script.

A valid constant name starts with a letter or underscore (no $ sign before the constant name).

Note: Unlike variables, constants are automatically global across the entire script.

HERE IS HOW YOU DO THAT:
define(name, value);

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

What needs to be included in the header of a wordpress plugin

A

/*
* Plugin Name: My Basics Plugin
* Plugin URI: https://example.com/plugins/the-basics/
* Description: Handle the basics with this plugin.
* Version: 1.10.3
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: John Smith
* Author URI: https://author.example.com/
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Update URI: https://example.com/my-plugin/
* Text Domain: my-basics-plugin
* Domain Path: /languages
* Requires Plugins: my-plugin, yet-another-plugin
*/

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

what is the update uri for?

A

this is a unique uri to diferentiate your plugin from others so it is not overwriten by other third party plugin updates

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

where can i find more information about plugin development in wordpress?

A

https://developer.wordpress.org/plugins/

20
Q

what is the text domain in wordpress plugin develppment header?

A

Use a text domain to denote all text belonging to your plugin. The text domain is a unique identifier to ensure WordPress can distinguish between all loaded translations. This increases portability and plays better with already existing WordPress tools.

The text domain must match the slug of the plugin. If your plugin is a single file called my-plugin.php or it is contained in a folder called my-plugin the domain name must be my-plugin. If your plugin is hosted on wordpress.org it must be the slug portion of your plugin URL (wordpress.org/plugins/<slug>).</slug>

The text domain name must use dashes and not underscores, be lower case, and have no spaces.

The text domain also needs to be added to the plugin header. WordPress uses it to internationalize your plugin metadata even when the plugin is disabled. The text domain should be same as the one used when loading the text domain.

21
Q

what is the domain path in your wordpress plugins header?

A

this is for the relative path to the languages directory

22
Q

in wordpress plugin development what is “the languages directory” for?

A

In WordPress plugin development, the languages directory is used to store translation files for the plugin, allowing it to be translated into multiple languages. WordPress is a global platform, and offering your plugin in different languages helps to make it accessible to a wider audience.

Here’s a breakdown of how the languages directory works:

Translation Files: The languages directory contains .po and .mo files, which are used for localization and internationalization. The .po (Portable Object) files are human-readable files that store the actual strings and their translations. The .mo (Machine Object) files are the compiled versions of .po files, used by WordPress to display the translated content.

23
Q

what if your wordpress plugin requres the use of another plugin?

A

you may ad this information to the head in your wordpress plugin file.

24
Q

what is the first three parts of the wordpress page lifecycle?

A
  1. checks front end requests(visiters loading a page on front end)
  2. checks if there is an admin request(someone access the adment panel)
  3. checks if there is an ajax request

for more information on this lifecycle go here: https://tommcfarlin.com/wordpress-page-lifecycle/

25
Q

why is it iportant to know the page lifesycle when developing in wordpress?

A

this gives you more information about how wordpress works under the hood. knowing the order and priority of the different plugins ect helps you trouble shoot if you are using a php hook that is not working for some reason

26
Q

how do you make an if statement

A

if(3 < 10){

echo “there is less than ten”;
}

27
Q

HOW DO YOU MAKE A SWITCH STATMETN

A

switch(37){
case 34:
echo “it is 34”;
break;
case 36:
echo “it is 36”;
break;
case 37:
echo “it is 37”;
break;
case 38:
echo “it is 38”;
break;
}

28
Q

when is it good to use a switch statment?

A

when you need to compare multiple comparisons or cases

29
Q

how do you add incriments in a while loop?

A

use the ++ statement to incriment. (kinda like += in javascript)

30
Q

how do you write a function in php

A

function functionName(){
echo “poo poo head” ;
}

31
Q

explain the return keyword

A

the return keyword holds data that is evaluated in a function for usage elseware. for example see below:
<?php

function testReturn($num1, $num2){
$sum = $num1 + $num2;
return $sum;
}
function testReturn2($num1, $num2){
$sum = $num1 + $num2;
}

echo testReturn(5,5); – this will show 10
echo testReturn2(6,5); this will not show anything because the function is not returning the data after evaluation. the function is just being exicuted. its done its job and nothing else because you didnt tell the function you want to use that evaluated data in elseware

?>

32
Q

what is the scope of a php variable inside a function

33
Q

what is the scope of a variable outside of any functions?

34
Q

how do you make a local variable global inside a function?

A

the global keyword

35
Q

Newer Way of creating a Constant

A

Now is possible to create a constant using the keyword “const” but it does not work the same as the define() function but it is very similar.

From PHP.net = https://www.php.net/manual/en/language.constants.syntax.php

When using the const keyword, only scalar data (boolean, integer, float and string) can be contained in constants prior to PHP 5.6. From PHP 5.6 onwards, it is possible to define a constant as a scalar expression, and it is also possible to define an array constant. It is possible to define constants as a resource, but it should be avoided, as it can cause unexpected results.

36
Q

what is the pow function in php?

A

this calculates exponents

37
Q

what is the rand fucntion do

A

gives you a random number

38
Q

what does the sqrt function do?

A

finds the square root of a number

39
Q

whate does the floor function do?

A

rounds DOWN! to nearewst intiger

40
Q

what does ceil function do?

A

rounds UP! to the nearest intiger

41
Q

what does the round function do?

A

rounds a decemal to the nearest intiger.

42
Q

how do you tell your php file to check for a post submission

A

you can use an if statement to check the sent associative array from the form then preform an action based on that information kinda like this:
if(isset($_POST[‘submit’])){
echo “logged in”;
}

43
Q

what is isset?

A

isset() is a function used in PHP programming to determine if a variable is set and is not null. It returns true if the variable exists and has a value other than null, and false otherwise.

44
Q

how do you create a database with the sql cli?

A

create database database name

45
Q

what function do you use to connect to your sql database?

A

mysqli_connect()