Home > Backend Development > PHP Tutorial > PHP learning officially sets sail (2)

PHP learning officially sets sail (2)

黄舟
Release: 2023-03-04 11:30:02
Original
1027 people have browsed it

Data type  
PHP supports integers, floating point numbers, strings, arrays and objects. The variable type is usually not determined by the programmer but by the PHP running process. You can use cast or the function settype() to convert a certain type of variable into a specified type.


The numerical value type can be an integer or a float. Points. You can use the following statements to assign a value:
$a = 1234; # You need to understand decimal numbers
$a = -123; # You need to understand negative numbers
$a = 0123; # Octal numbers ( Equal to 83 in decimal)
$a = 0x12; # Hexadecimal number (equal to 18 in decimal)
$a = 1.234; # Floating point number "double precision number" to understand
$a = 1.2e3; # Exponential form of double precision number

Just know the integers and decimals here. . . .

String  
Strings can be defined by fields enclosed in single quotes or double quotes. Note that the difference is that strings enclosed in single quotes are defined literally, while strings enclosed in double quotes can be expanded. Furthermore, you can use backslash\ in a double-quoted string to add escape sequences and conversion characters to the string. Examples are as follows:

$first = 'Hello'; 
$second = "World"; 
$full1 = "$first $second"; # 产生 Hello World 
$full2 = '$first $second';# 产生 $first $second
Copy after login

is used to concatenate two strings. Instead of +, please note that
$string=$first.$second; The result is HelloWorld

Operator PHP has commonly seen operators in C, C++ and Java. The precedence of these operators is also consistent. Assignment also uses "=". Arithmetic and Characters Only one of the following operators is related to characters:
$a + $b: Add
$a - $b: Subtract
$a * $b: Multiply
$a / $b: Divide
$a % $b: Modulo (remainder)
$a. $b: String connection logic and comparison logic operators are:
$a || $b: or
$a or $b: or
$a && $b: AND
$a and $b: AND
$a xor $b: XOR (when $a or $b is true is true, if both are the same, it is false)
! $a: Not
Comparison operators are:
$a == $b: Equal
$a != $b: Not equal
$a < $b: less than
$a <= $b: less than or equal to
$a > $b: greater than
$a >= $b: greater than or equal to
Like C, PHP also has the triple operator (?:). Bit operators also exist in PHP.

It’s really simple. .

Control process structure
PHP has the same process control as C.
if (expression two)
. . .
}
elseif (expression two)
{
. . .
}
else
{
. . .
}

switch is the best replacement for multiple if-elseif-else structures:

switch ($i) 
{ 
case 0: 
print "i equals 0"; 
case 1: 
print "i equals 1"; 
case 2: 
print "i equals 2"; 
}
Copy after login

Loop structure
while (expression Formula)
{
. . .
}



do
{
. . .
}
while (expression );



for (expression one; expression two; expression three)
{
. . .
}

Also When using a loop foreach, say


break, continue
break to interrupt the current loop control structure.
continue is used to jump out of the remaining current loop and continue executing the next loop.


These are very simple, the same as C language, so we can forget them in a nutshell. . .

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template