PHP移动互联网开发笔记(2)??变量及常量
一、PHP5.4的基本语法格式
1、PHP的分割符
view source
print ?
1. $php=true; //分号结束语句
2. if($php){
3. echo "真"; //分号结束语句
4. } //大括号结束语句
5. ?>
2、PHP注释与语法标识
(1)、单行注释 // 来源于C++的注释 # 来源于C语言的注释
(2)、多行注释 /* */ 来源于C语言的注释
3、函数的使用格式
(1) 返回值 函数名()
(2) 返回值 函数名(参数, 参数)
(3) 函数名(参数, 参数, 返回变量)
(4) 返回值 函数名(.. ..)通用符 // PHP5.4的用法
二、PHP5.4的变量与变量的数据类型
变量是由一个美元符“$"开头,”$"后是一个标识符。标识字符串只字母、数字、下划线组成且不可以数字开头。
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. ?>
变量命名的方式
(1)单词之间直接连接
$titlekeyword
(2)单词之间用下划线连接
$title_keyword
(3)单词之间首字母大写(驼峰)
$titleKeyword
PHP的数据类型如下:
(1)字符串(String):单引号(简单引号)或双引号(功能引号)内的内容
(2)整型(integer): -2^32
(3)浮点符(float或double) 1.8E+308 (1.8 x 10^308)
(4)布尔型(boolean) true或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. ?>
(7)资源类型(Resouce) 系统数据资源
资源是一个特殊的数据类型,无法直接获得变量,需要通过专门的函数来访问:
数据库访问必须通过Mysql函数库、Mysqli函数库或PDO函数库实现。
文件访问必须通过FileSystem函数库实现。
目录操作必须通过Directory函数库实现。
图像操作必须通过GD函数库实现。
(8)空值(NULL)
三、PHP5.4的系统常量与自定义常量
常量在程序执行期间无法改变数据,常量的作用域是全局的。常量的命名与变量相似,只是不带“$"符号。一个有效的常量由字母或者下划线开头,一般在PHP中常量都为大写字母而且又分为系统常量和自定义常量。
系统常量范例:
__FILE__ 默认常量,是指PHP程序文件名及路径
__LINE__ 默认常量,是指PHP程序的行数
__CLASS__ 类的名称
在PHP中通过define()函数来定义一个常量,其语法格式为:
bool define(string $name, mixed $value [, bool case_$insensitive])
name:常量的名称
value:常量的值
insensitive:指定常量名称是否区分大小写。如果设置为true则不区分大小写;如果设置为false则区分大小写,默认值为false。
view source
print ?
1. define("COLOR", "red"); //定义一个常量COLOR,值为red
2. echo COLOR."
3. "; //输出常量COLOR的值
可变变量
view source
print ?
1. $a="b"
2. $$a="123" //可变变量
3. echo $b;
输出结果为:123
在字符串中输出变量要使用双引号
view source
print ?
1. $a=50;
2. //echo '我有$a元人民币"; 单引号
3. echo "我有$a元人民币";
在双引号中可以执行的转意字符更多,比如 \n \t \r
判断数据类型
view source
print ?
1. $a="-5";
2. //$a=-5;
3. var_dump($a);

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

AI Hentai Generator
Generate AI Hentai for free.

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 this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

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

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
