Table of Contents
PHP Mobile Internet Development Notes (2) - Variables and Constants
Home Backend Development PHP Tutorial PHP Mobile Internet Development Notes (2) - Variables and Constants_PHP Tutorial

PHP Mobile Internet Development Notes (2) - Variables and Constants_PHP Tutorial

Jul 13, 2016 am 10:18 AM
internet variable constant

PHP Mobile Internet Development Notes (2) - Variables and Constants

1. Basic syntax format of PHP5.4

1. PHP separator

view source print? 1.$php=true; //分号结束语句 2.if($php){ 3.echo ; //分号结束语句 4.} //大括号结束语句 5.?>

2. PHP comments and syntax markers

(1), single line comment //Comment from C++ #Comment from C language

(2), multi-line comments /* */ Comments from C language

3. Function usage format

(1) Return value function name()

(2) Return value function name (parameter, parameter)

(3) Function name (parameters, parameters, return variables)

(4) Return value function name (.. ..) universal character // Usage of PHP5.4

2. PHP5.4 variables and variable data types

A variable starts with a dollar sign "$," followed by an identifier. The identification string only consists of letters, numbers, and underscores and cannot start with a number.

view source print? 01.$php=true; //分号结束语句 02.if($php){ 03.echo ; //分号结束语句 04.} //大括号结束语句 05. 06.$url=blog.csdn.net/dawanganban; //定义变量 07.echo $url; 08.unset($url); //删除一个变量url 09.echo $url; 10.?> How to name variables

(1) Direct connection between words

$titlekeyword

(2) Use underlines to connect words

$title_keyword

(3) Capitalize the first letter between words (hump case)

$titleKeyword

PHP’s data types are as follows:

(1) String: Content within single quotes (simple quotes) or double quotes (functional quotes)

(2) Integer: -2^32

(3) Floating point character (float or double) 1.8E+308 (1.8 x 10^308)

(4) boolean true or false

(5)Array

(6) Object

view source print? 01.class Person{ 02.public $userName=阳光小强; 03.public function getMsg(){ 04.echo 姓名为:.$this->userName; 05.} 06.} 07.$p=new Person(); 08.$p->getMsg(); 09. 10.?> PHP Mobile Internet Development Notes (2) - Variables and Constants_PHP Tutorial

(7) Resource type (Resouce) System data resource

Resource is a special data type. Variables cannot be obtained directly and need to be accessed through special functions:

Database access must be achieved through the Mysql function library, Mysqli function library or PDO function library.

File access must be implemented through the FileSystem function library.

Directory operations must be implemented through the Directory function library.

Image operations must be implemented through the GD function library.

(8)NULL

3. System constants and custom constants of PHP5.4

Constants cannot change data during program execution, and the scope of constants is global. The naming of constants is similar to variables, except without the "$ symbol. A valid constant starts with a letter or underscore. Generally, constants in PHP are capital letters and are divided into system constants and custom constants.

System constant example:

__FILE__ default constant, refers to the PHP program file name and path

__LINE__ is the default constant, which refers to the number of lines in the PHP program

__CLASS__ The name of the class

In PHP, define a constant through the define() function. Its syntax format is:

bool define(string $name, mixed $value [, bool case_$insensitive])

name: the name of the constant

value: value of constant

insensitive: Specifies whether the constant name is case-sensitive. If set to true, it is case-insensitive; if set to false, it is case-sensitive. The default value is false.

view source print? 1.define(COLOR, red); //定义一个常量COLOR,值为red 2.echo COLOR. 3.; //输出常量COLOR的值

Variable variables

view source print? 1.$a=b 2.$$a=123 //可变变量 3.echo $b; The output result is: 123

Use double quotes when outputting variables in a string

view source print? 1.$a=50; 2.//echo '我有$a元人民币; 单引号 3.echo 我有$a元人民币; There are more escape characters that can be executed in double quotes, such as

Determine data type

view source print? 1.$a=-5; 2.//$a=-5; 3.var_dump($a);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/885677.htmlTechArticlePHP Mobile Internet Development Notes (2) - Variables and Constants 1. Basic syntax format of PHP5.4 1. PHP delimiter view source print? 1. $php =true; //Semicolon ends statement 2. if ( $php...
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)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 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)

Fix: Network connection issue that prevents access to the Internet in Windows 11 Safe Mode Fix: Network connection issue that prevents access to the Internet in Windows 11 Safe Mode Sep 23, 2023 pm 01:13 PM

Having no internet connection on your Windows 11 computer in Safe Mode with Networking can be frustrating, especially when diagnosing and troubleshooting system issues. In this guide, we will discuss the potential causes of the problem and list effective solutions to ensure you can access the internet in Safe Mode. Why is there no internet in safe mode with networking? The network adapter is incompatible or not loading correctly. Third-party firewalls, security software, or antivirus software may interfere with network connections in safe mode. Network service is not running. Malware Infection What should I do if the Internet cannot be used in Safe Mode on Windows 11? Before performing advanced troubleshooting steps, you should consider performing the following checks: Make sure to use

What are constants in C language? Can you give an example? What are constants in C language? Can you give an example? Aug 28, 2023 pm 10:45 PM

A constant is also called a variable and once defined, its value does not change during the execution of the program. Therefore, we can declare a variable as a constant referencing a fixed value. It is also called text. Constants must be defined using the Const keyword. Syntax The syntax of constants used in C programming language is as follows - consttypeVariableName; (or) consttype*VariableName; Different types of constants The different types of constants used in C programming language are as follows: Integer constants - For example: 1,0,34, 4567 Floating point constants - Example: 0.0, 156.89, 23.456 Octal and Hexadecimal constants - Example: Hex: 0x2a, 0xaa.. Octal

How to create a constant in Python? How to create a constant in Python? Aug 29, 2023 pm 05:17 PM

Constants and variables are used to store data values ​​in programming. A variable usually refers to a value that can change over time. A constant is a type of variable whose value cannot be changed during program execution. There are only six built-in constants available in Python, they are False, True, None, NotImplemented, Ellipsis(...) and __debug__. Apart from these constants, Python does not have any built-in data types to store constant values. Example An example of a constant is demonstrated below - False=100 outputs SyntaxError:cannotassigntoFalseFalse is a built-in constant in Python that is used to store boolean values

A guide to using Windows 11 and 10 environment variables for profiling A guide to using Windows 11 and 10 environment variables for profiling Nov 01, 2023 pm 08:13 PM

Environment variables are the path to the location (or environment) where applications and programs run. They can be created, edited, managed or deleted by the user and come in handy when managing the behavior of certain processes. Here's how to create a configuration file to manage multiple variables simultaneously without having to edit them individually on Windows. How to use profiles in environment variables Windows 11 and 10 On Windows, there are two sets of environment variables – user variables (apply to the current user) and system variables (apply globally). However, using a tool like PowerToys, you can create a separate configuration file to add new and existing variables and manage them all at once. Here’s how: Step 1: Install PowerToysPowerTo

Strict mode for variables in PHP7: how to reduce potential bugs? Strict mode for variables in PHP7: how to reduce potential bugs? Oct 19, 2023 am 10:01 AM

Strict mode was introduced in PHP7, which can help developers reduce potential errors. This article will explain what strict mode is and how to use strict mode in PHP7 to reduce errors. At the same time, the application of strict mode will be demonstrated through code examples. 1. What is strict mode? Strict mode is a feature in PHP7 that can help developers write more standardized code and reduce some common errors. In strict mode, there will be strict restrictions and detection on variable declaration, type checking, function calling, etc. Pass

In Java, is it possible to define a constant using only the final keyword? In Java, is it possible to define a constant using only the final keyword? Sep 20, 2023 pm 04:17 PM

A constant variable is a variable whose value is fixed and only one copy exists in the program. Once you declare a constant variable and assign a value to it, you cannot change its value again throughout the program. Unlike other languages, Java does not directly support constants. However, you can still create a constant by declaring a variable static and final. Static - Once you declare a static variable, they will be loaded into memory at compile time, i.e. only one copy will be available. Final - Once you declare a final variable, its value cannot be modified. Therefore, you can create a constant in Java by declaring the instance variable as static and final. Example Demonstration classData{&am

What are instance variables in Java What are instance variables in Java Feb 19, 2024 pm 07:55 PM

Instance variables in Java refer to variables defined in the class, not in the method or constructor. Instance variables are also called member variables. Each instance of a class has its own copy of the instance variable. Instance variables are initialized during object creation, and their state is saved and maintained throughout the object's lifetime. Instance variable definitions are usually placed at the top of the class and can be declared with any access modifier, which can be public, private, protected, or the default access modifier. It depends on what we want this to be

How to get variables from PHP method using Ajax? How to get variables from PHP method using Ajax? Mar 09, 2024 pm 05:36 PM

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

See all articles