Home Backend Development PHP Tutorial A brief discussion of PHP syntax 1_PHP tutorial

A brief discussion of PHP syntax 1_PHP tutorial

Jul 13, 2016 pm 05:27 PM
html php Can Basic I of grammar

In the article "Talk about HTML syntax", I have introduced basic HTML syntax. It is possible to compile a static Web page, but it is very important to dynamically interact information. For example, the membership system of some websites requires the operation of back-end programs for member registration and login. The CGI programs used by many websites are mainly written in Perl, ASP, Java, and PHP, and what we are going to use is PHP. It's completely free, thanks to those obscure programmers. The structure of PHP is similar to the C language, which is in compliance with the "learn in one place, program anywhere" mentioned in the C language. I believe that people who have learned the C language can easily get started with PHP. Let’s introduce some PHP syntax first. This article is suitable for beginners to learn.
There are also some differences between PHP and C language, or it may be more flexible than C language to some extent. In C language, variables must be defined before they can be used. In PHP, variables do not need to be defined in advance and can be used directly. The type of the variable is automatically generated when assigning a value. The types of PHP variables are divided into: integer (int), double (double), string (string), array (array), and object (object).
When the integer size exceeds its range, it is automatically converted to double precision. The value range is as follows:
┌─────┬─────┬──────┬──── ────────┐
│ Declaration type │ Length (bits) │ Length (bytes) │ Value range │
├─────┼─────┼─── ───┼────────────┤
│ int │ 32 │ 4 │-2147483647~2147483647 │
├─────┼─────┼── ────┼────────────┤
│ double │ 32 │ 4 │ 1.7E-308~1.7E+308 │
└─────┴── ───┴──────┴────────────┘
String, usually represented by "" (double quotes). It can also be expressed with (single quotes), as follows:
$a="abc";
$b="abc$a";
$c=abc$a;
$d="" cde"";
$e="cde";
Various variables in PHP are distinguished by adding "$" before the variable name.
Note that the content of $b is abcabc, the content of $c is abc$a, the content of $d is "cde", and the content of $e is also "cde". It can be seen that the variable names in the content in double quotes will be replaced, but those in single quotes will not. The content in double quotation marks needs to be escaped, such as $, which should be represented by $, but the content in single quotation marks should not be escaped.


The array syntax in PHP is:
Array name [index]
The index can be a number or a text. But it is not recommended to use text because it does not make much sense. It is also more flexible than other languages ​​for arrays. For example:
$names[]=100;
$names[]=200;
$names[]="hi,how are you ";
$names[]=98.5;
$names[]=1.7E+23;
$num=count($names);
for ($i=0;$i echo "$names[$i]
";
}
?>
It can be seen that the elements in an array are not necessarily of the same type , this is the "live" part of PHP arrays.
Using objects makes it easier for programmers to maintain and makes programs more readable. Compared with other languages, PHP is much simpler. It only has categories, methods, attributes, extensions, etc.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531880.htmlTechArticleIn the article "Talk about HTML syntax", I have introduced the basic HTML syntax. It is possible to compile a static Web page, but it is very important to dynamically interact information. For example, the membership system of some websites will...
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

Video Face Swap

Video Face Swap

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

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)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1263
29
C# Tutorial
1236
24
Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

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 in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

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

React's Role in HTML: Enhancing User Experience React's Role in HTML: Enhancing User Experience Apr 09, 2025 am 12:11 AM

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

See all articles