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

PHP learning officially sets sail (2)

Dec 28, 2016 am 09:08 AM
php

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. . .

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

See all articles