PHP语言基础02 By ACReaper
其实写这些php的文章是很基础的,而且跳跃过了很多语法点,因为C语言和C++学的比较好,很多类似,只是写出了不同的地方,方便学习。分享出来也方便和我同样情况的人学,如果是什么都没学过的,不懂数据结构,不懂算法,不懂C,最好不要看我写的,而是因该去买本比较好的参考书来参考。
02.1PHP中的常量的定义
define("CONSTANT_NAME",value[,case_senstivitty]);
其中“CONSTANt_NAME”是常量,是一个字符串,value即为值(为任何合法的php表达式,包含对象和数组)。而最后一个由字面意思就可知道其意思为区分大小写。默认为区分值为true,反之为false。常量和C一样,一般写成大写。
02.2运算符
php包含三种运算符,一元、二元、三元运算符。php类型转变原理和C类似,向存得多的方向转换,下面是具体规则。
转换方向。不能逆向,否则数据丢失!
1.向存得最多的类型转换,即表示范围最大的。
2.字符串向整型转换,不够则向real型转换。
3.整型向real类型转换
而boolean型,Null型,Resource型也和整型类似,其实可以理解为本质就是与整数有关系,至于原因你去看内核实现代码就知道。
Boolean:False = 0,True = 1
Null = 0;
Resource = The resource’s #(id)
02.2.1说说二元运算符
首先php中比较特殊的二元运算符是 串联运算符(.) 其它的和C语言一样。
其次所有的数学运算符只计算数字操作符,遇到其它类型的按照前面讲的转换。
下面重点介绍串联运算符(.)
串联运算符只做两个字符串的串联,也就是所这个运算符只处理字符串,所以任何非字符串的操作数都会被首先转换成字符串。这其实就像C++中的重载运算符,你首先要规定好重载运算符所运算的类型,而且强制转换。
eg:
$year = 2013;
print "The year is" . $year;
则会把$year在内部转换成字符串"2000"再与前面的字符串“The year is”串联起来。
02.2.2引用赋值运算符。
$name = "Judy";
$name_alias = & $name;
$name_alias = "Jonathan";
print $name;
则输出Jonathan。
由此我们可以得出php中所谓的引用和C++中的一样,其实其本质还是基于C的指针。也就是相当与给变量另外取一个别名。
当通过引用方式返回函数的值,需用引用符号了说明。
$retval = & function_return_by_reference();
02.3比较运算符(只讲 ==,===,!==)
==
检查两个操作数是否相等!,如需类型转换即,规则是 1 == “1”返回true,1 == 1也返回true。
===
全等与==类似,但是类型必须一样,不执行自动类型转换所以1 === “1”逻辑值为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











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

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.

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 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 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 is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

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.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
