Learn variables and operations in PHP while actually coding them.
準備
After installing PHP, let’s actually code it.
PHP installation
Change permissions
PHP’s “DocumentRoot” is “/ var / www / html” by default.
Since the html authority is the administrator, change it to general.
chown
Change the owner with the chown command.
sudo chown username: username / var / www / html
index.php creation
Create an index.php file under the html folder.
vim /var/www/html/index.php
You can use vi instead of the vim editor.You can also create it with an editor and upload it.
PHP variables
Those who are new to programming may be confused.
Think of a variable as a “box” that stores “some data”.
For example, at a pizza shop, we will deliver “pizza” in a “box”. At home, open the “box” and take out the “pizza” to eat.
Of course, in addition to “pizza”, you can pack various things such as “potato” and “juice”.
constant
Some variables are “constants” that do not change their contents.
Once declared, the contents do not change during the processing of the program.
constant
define("constant", "abc");
Declare a constant with define. The character string “abc” is stored in the constant name “constant”.
Variable.logical value
A logical value represents true or false.I’m not sure at first, but it is used for comparison results.
Logical value
$temp = true;
Set true to the variable name “temp”.
Variable.integer
Set an integer value for the variable.
integer
$temp = 123;
Set 123 to the variable name “temp”.
Variable. Floating point
Set the variable to a floating point number.
Floating point
$temp = 123.456;
Set 123.456 to the variable name “temp”.
Variable.string
Set the character string to the variable.
整数
$temp = "CODESE";
Set CODESE to the variable name “temp”.
It’s very easy. Depending on the language, it may be necessary to change the declaration according to the data or secure an area. You don’t need PHP. If you store more data than the area or forget to release it, serious things will happen.
PHP arithmetic
The four arithmetic operations are calculated using the symbols “+”, “-“, “/”, “*”.
Four arithmetic operations
Addition
$temp = 1 + 1;
Subtraction
$temp = 1 - 1;
Multiply
$temp = 2 * 2;
division
$temp = 2 / 2;
Operations using variables
Calculate using variables.
Four arithmetic operations. Variables
$temp10 = 10;
$temp20 = 20;
Addition
$temp = $temp10 + $temp20;
Subtraction
$temp = $temp10 - $temp20;
Multiply
$temp = $temp10 * $temp20;
division
$temp = $temp10 / $temp20;
Practice
Enter the code below to get it working.
All you have to do is access the IP address of the guest OS with a web browser.
For example, if “192.168.0.100” is the IP address of the guest OS, it will be as follows.