PHP Basic Notes-NO.1

Original ID: GUIDM

I was busy in July and didn't have time to update, and I didn't go to CSDN very much. I didn't read all the private messages sent by everyone in time. I'm very sorry everyone.

Recently, I am learning PHP, and the advanced version of JavaScript has been temporarily suspended. After learning PHP is updating the front-end content.

This column of PHP is simply a record of study notes. thanks for your support.

Table of contents

1. Basic introduction

2. PHP program

 

 3. PHP variables

 


1. Basic introduction

  • PHP: (Hypertext Preprocessor hypertext preprocessor), a widely used open source general-purpose server scripting language, suitable for web development and embedded in HTML.
  • A programming language that does not require compilation and is directly executed by an interpreter/virtual machine
  • PHP program execution flow:



2. PHP program

  • Default extension: .php
  • The php file can contain: html, css, JavaScript code.

Several tags:

1. ASP tag:

<% PHP代码 %>

2. Short mark:

<? php代码 ?>

3. Script tag:

<script language="php">
php代码
</script>

4. Standard mark:

<?php
PHP代码
?>
  1. Commonly used tags are: Standard tags.
  2. ASP and short tags are basically deprecated, if you want to use it, you need to open it in the configuration file

PHP syntax:

<?php
php代码
?>
  1. ";" indicates the end of the statement.
  2. {} indicates the end of a statement.
  3. The closing tag of a PHP code block also automatically indicates a semicolon (so it is not necessary to use a semicolon on the last line of a PHP code block)

note

  • (#)//Single line comment
  • /* */ Multi-line comment
/*
 *@作者:
 *@功能:
*/

Habit: All code must be commented in the process of writing.


first output function

  • The echo() function outputs one or more strings.
<?php
echo "Hello world!";
?>


 3. PHP variables

Variable definition: add the corresponding variable name (memory) in the system.

  • Variable declaration: $variable name.
<?php
$a=1;
echo $a;
?>

Assignment: Data can be assigned to variables (can be done at the same time as the definition).

  • Variable Naming Rules

  1. Cannot begin with a number.
  2. There can be no spaces in between.
  3. Three nomenclatures:
Underline nomenclature: link 2 English words with an underline. Such as: one_two
Small hump nomenclature: the first letter of the second word is capitalized, such as: newFile
Big hump nomenclature: the first letter of all words is capitalized, such as: NewFile

 The mix of html and PHP needs to be under the PHP file.

The same variable name together, the following sentence will overwrite the previous sentence.


mutable variable

If the value stored in a variable happens to be the name of another variable, then you can directly get the value of another variable by accessing one variable: add an extra $ sign before the variable.

<?php
$a='b';
$b='bb';
echo $$a;//bb
?>

process:

  1. Find $a, interpret the result as "b";
  2. Bind the previous $ sign to the result b;
  3. The analysis result is bb;

variable value

Assign a variable to another variable.

  1. Value transfer: copy the value saved by a variable, and save the new value to another variable (the two variables have nothing to do with each other). $a=$b
  2. Pass by reference: Pass the memory address where the value saved by the variable is located to another variable. Two variables point to the same memory space (the two variables have the same value.) $new variable=&$old variable
//值传递:
<?php
$a=10;
$b=$a;
echo $b;//10
>
//引用传递
<?php
$c=10;
$d=&$c;
echo $d;//10
>

Several partitions of memory:

Stack area, code segment, data segment, heap area.

Guess you like

Origin blog.csdn.net/m0_61901625/article/details/126109770