PHP惯用的一些基本函数(一)
PHP常用的一些基本函数(一)
1.PHP声明和使用常量
?? define('CONSTANT','100');类似于这样的就是声明一个常量,一旦声明在其他地方是不能修改的。一般我们的常量都是用大写字母组成,而且常量前没有$符号。
2.PHP的复合运算符
$a += $b; 等价于 $a = $a + $b
$a -= $b; 等价于 $a = $a - $b
$a .= $b; 等价于 $a = $a.$b 这个是连接字符串用的不是(乘法*)
3.$a++ ++$a的区别
$a=4;
echo ++$a;
$a首先将变量$a加1,再将加1后的结果赋值给原变量,$a变成5,整个表达式的值就是5
$a=4;
echo $a++;
$a的值被返回到屏幕上,然后$a在加1,这个表达式的值是4,$a的值是5。
4.&作为引用的作用
$a=5;
$b=$a;
这两行代码首先产生一个$a的副本,然后将它保存到$b中。如果随后$a的值改变了,$a=7了,$b的值不会变。仍然是5.
$a=5;
$b=&$a;
这里使用了&从而就不产生$a的副本,如果随后$a的值改变了,$a=7,那么$b的值也是变成了$b=7。引用将$a和$b都指向了内存的相同地址
5.一个老是记不住的标签
$a && $b??必须是两者都是true,才为true【AND】必须同时成立
$a || $b??一者为true就是true??????【OR】
6.三元操作符
($grade >= 55 ? 'Passed' : 'Failed')
condition???? val is true?? val is false
7.@操作符
$a = @(0/5);[email protected],就会产生一个除0的警告,有了这个操作符,这个警告就被抑制住。
8.instanceof操作符
作用是允许检查一个对象是否是特定类的实例
class sampleClass{}
$my = new sampleClass();
if($my instanceof sampleClass){}
9.函数:number_format()
number_format(number,decimals,decimalpoint,separator)
参数说明:
number必需。要格式化的数字。如果未设置其他参数,则数字会被格式化为不带小数点且以逗号 (,) 作为分隔符。
decimals 可选。规定多少个小数。如果设置了该参数,则使用点号 (.) 作为小数点来格式化数字。
decimalpoint 可选。规定用作小数点的字符串。
separator 可选。规定用作千位分隔符的字符串。仅使用该参数的第一个字符。比如 "xyz" 仅输出 "x"。注释:如果设置了该参数,那么所有其他参数都是必需的。
echo number_format("1000000.777");//这里格式化之后,所有的小数点都没有了
echo number_format("1000000",2);
echo number_format("1000000",2,",",".");
?>
输出:
1,000,000
1,000,000.00
1.000.000,00
10.函数settype()和gettype()
$va = 54;
echo gettype($va);//这是输出$va的类型integer
settype($va,'double');//这是设置它为双精度型
可以用is_double();来测试,返回值是true or false.

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



In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

Detailed explanation of the role and usage of the echo keyword in PHP PHP is a widely used server-side scripting language, which is widely used in web development. The echo keyword is a method used to output content in PHP. This article will introduce in detail the function and use of the echo keyword. Function: The main function of the echo keyword is to output content to the browser. In web development, we need to dynamically present data to the front-end page. At this time, we can use the echo keyword to output the data to the page. e

With the development of the Internet and the advancement of information technology, the era of big data has arrived, and fields such as data analysis and machine learning have also been widely used. In these fields, task scheduling is an inevitable problem. How to achieve efficient task scheduling is crucial to improving efficiency. In this article, we will introduce how to use Golang's web framework Echo framework to implement distributed task scheduling. 1. Introduction to the Echo framework Echo is a high-performance, scalable, lightweight GoWeb framework. It is based on HTTP

The most popular Go frameworks at present are: Gin: lightweight, high-performance web framework, simple and easy to use. Echo: A fast, highly customizable web framework that provides high-performance routing and middleware. GorillaMux: A fast and flexible multiplexer that provides advanced routing configuration options. Fiber: A performance-optimized, high-performance web framework that handles high concurrent requests. Martini: A modular web framework with object-oriented design that provides a rich feature set.

As a fast and efficient programming language, Go language has always been favored by programmers. In the Go language ecosystem, frameworks play a vital role in helping developers build applications faster. This article will introduce five Go language frameworks to let you understand their characteristics and usage. 1. Gin framework The Gin framework is a lightweight Web framework with fast and high performance characteristics. Use the Gin framework to quickly build RESTful APIs and web applications. Here is a simple example code:

As an efficient and modern programming language, Go language is widely favored by developers. In the Go language, there are many excellent frameworks that can help developers quickly build efficient and stable applications. This article will introduce some popular frameworks in the Go language and provide some specific code examples. Gin framework Gin is a very popular Goweb framework that provides the ability to quickly develop APIs. The Gin framework has the characteristics of high performance, ease of use, and lightweight, and is widely used in back-end development of Internet companies.
