Chapter 4_PHP Basic Syntax_PHP Tutorial
1. The first PHP program
<span 1</span> <span //</span><span 弱爆了有木有</span> <span 2</span> <?<span php </span><span 3</span> <span echo</span> "<span Hello PHP!'; </span><span 4</span> ?>
2.PHP supports a total of 8 basic data types, including 4 scalar types: boolean (Boolean type), integer (integer type), float (floating point type, also called double), string (string), 2 composite types: array (array), object (object), 2 special types: resource (resource), NULL (empty type)
3. The function var_dump can be used to print relevant information about variables.
<span 1</span> <?<span php </span><span 2</span> <span var_dump</span>((bool) <span false</span><span ); </span><span 3</span> <span var_dump</span>((bool) 0<span ); </span><span 4</span> <span var_dump</span>((bool) 0.0<span ); </span><span 5</span> <span var_dump</span>((bool) ''<span ); </span><span 6</span> <span var_dump</span>((bool) "0"<span ); </span><span 7</span> <span var_dump</span>((bool) <span array</span><span ()); </span><span 8</span> <span var_dump</span>((bool) <span NULL</span><span ); </span><span 9</span> ?>
4. About integers.
In 32-bit operating systems, the valid range of integers is -2147483648~+2147483647. If it exceeds this range, it will be interpreted as a floating point number (float) by the PHP engine.
Add 0 in octal and 0x in hexadecimal (the number 0 instead of the letter O)
<span 1</span> <?<span php </span><span 2</span> <span $dec_int</span>=63<span ; </span><span 3</span> <span var_dump</span>(<span $dec_int</span><span ); </span><span 4</span> <span 5</span> <span $oct_int</span>=077<span ; </span><span 6</span> <span var_dump</span>(<span $oct_int</span><span ); </span><span 7</span> <span 8</span> <span $hex_int</span>=0x3f<span ; </span><span 9</span> <span var_dump</span>(<span $hex_int</span><span ); </span><span 10</span> ?>
5. String type
There are three ways to define strings, namely single quotes ('), double quotes (") and delimiters (<<<). The difference between the first two is that if the string contains variables Name, the variable name in double quotes will be replaced by the actual value, and the variable name in single quotes will be output directly as ordinary characters
.<span 1</span> <?<span php </span><span 2</span> <span $name</span>='麦兜'<span ; </span><span 3</span> <span $age</span>=19<span ; </span><span 4</span> <span echo</span> '本人大名$name,年方$age'<span ; </span><span 5</span> <span echo</span> '<p>'<span ; </span><span 6</span> <span echo</span> "本人大名<span $name</span>,年方<span $age</span>"<span ; </span><span 7</span> ?>
The use of delimiters is as follows:
<span 1</span> <?<span php </span><span 2</span> <span echo</span> <<<<span MY_STR </span><span 3</span> <span 我是PHP初学者 </span><span 4</span> <span MY_STR; //最后结尾的标识符前面不能有空格或者缩进,必须顶咯 </span><span 5</span> ?>
6. Object type
<span 1</span> <?<span php </span><span 2</span> <span class</span><span Person { </span><span 3</span> <span public</span> <span $name</span><span ; </span><span 4</span> <span private</span> <span $age</span><span ; </span><span 5</span> <span 6</span> <span function</span> Person(<span $name</span>,<span $age</span><span ){ </span><span 7</span> <span $this</span>->name=<span $name</span><span ; </span><span 8</span> <span $this</span>->age=<span $age</span><span ; </span><span 9</span> <span } </span><span 10</span> <span 11</span> <span function</span><span getInfo(){ </span><span 12</span> <span echo</span> '我叫'.<span $this</span>->name.'<br>我今年'.<span $this</span>->age.'岁了'<span ; </span><span 13</span> <span } </span><span 14</span> <span } </span><span 15</span> <span $boy</span> = <span new</span> Person("kimi",5<span ); </span><span 16</span> <span $boy</span>-><span getInfo(); </span><span 17</span> ?>
7. Type conversion
print_r() Displays easy-to-understand information about a variable. If given is string, integer or float, the variable will be printed value itself. If array is given, the keys and elements
will be displayed in a certain format.
<span 1</span> <?<span php </span><span 2</span> <span $temp_var</span>=3.141592653<span ; </span><span 3</span> <span $var1</span>=(<span string</span>)<span $temp_var</span><span ; </span><span 4</span> <span echo</span> "<p><span $var1</span>"<span ; </span><span 5</span> <span 6</span> <span $temp_var</span>='Kimi'<span ; </span><span 7</span> <span $var2</span>=(<span array</span>)<span $temp_var</span><span ; </span><span 8</span> <span echo</span> '<p>'<span ; </span><span 9</span> <span print_r</span>(<span $var2</span><span ); </span><span 10</span> <span 11</span> <span $temp_var</span>='Cindy'<span ; </span><span 12</span> <span $var3</span>=(<span unset</span>)<span $temp_var</span><span ; </span><span 13</span> <span echo</span> '<p>'<span ; </span><span 14</span> <span var_dump</span>(<span $var3</span><span ); </span><span 15</span> ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
