PHP速学
基本代码
<?php
echo "Hello world";
?>
变量定义
<?php
$a=true;
$bool_value=true;
$integer_value=9;
$float_value=3.1415926;
$string_value="Pi_is_{{$float_value}}.";
echo $string_value;//Pi_is_{3.1415926}.
?>
输出
<?php
$str="string_";
$return_value=print($str);//success: return 1, faile: return 0
echo $return_value;//no return value
$return_value=printf("value:%f",3.1415926);
$str=sprintf("value:%f",3.1415926);//print to variable str
echo $str;
?>
数据结构-数组
<?php
$season[0]='spring';
$season[1]='summer';
$season[2]='autumn';
$season[3]='winter'; $map['key1']='value1';
$map['key2']='value2'; //season & map are all array
echo $season;
echo $map;
?>
数据结构-对象
<?php
class Point
{
private $id=0;
public $x,$y;
function __construct($x,$y)
{
$this->x=$x;
$this->y=$y;
}
function Print_info()
{
echo $this->id,"<br>";
echo $this->x,"<br>";
echo $this->y,"<br>";
}
}
$p=new Point(1,3);
$p->Print_info();
?>
数据结构-资源数据类型
类似于句柄的概念,使用完成后需要销毁。
数据结构-空类型
<?php
$uninitialized;
$null_var1=null;
$var="123";
unset($var);
//this three variable are null
?>
类型转换
<?php
//int or integer, float or double or real, string, array, object, bool or boolean
//if an string starts with number, it will be truncated to a number in arithmetic
//if an string starts with non-number, it will be zero in arithmetic
//it's ok to run "3.14abc"+6, so double can be neglectable
echo (double)"a3.1415926abc"; //intval, doubleval, floatval, floatval, strval
echo intval(3.1415926); //var is supposed by array, boolean, float, integer or int, null, object, unknow, string
$value="3.1415926";
$return_value = settype($value,int);//success: 1
echo $value;
?>
变量
值传递/引用传递,可变变量
<?php
//by value
$int1=1;
$int2=int1;
$int2=5;
echo $int1,"<br>",$int2,"<br>";//1 5 //by reference
$int1=1;
$int2=& $int1;
$int2=5;
echo $int1,"<br>",$int2,"<br>";//5 5 //Variable variables: use variable value to define a variable named value
$sun="hot";
$$sun="moon";//equal to $hot="moon"
//${$sun} is eual to $hot
echo $sun,"<br>",${$sun},"<br>";
//user aliases
echo $hot,"<br>";
?>
超级全局变量SuperGlobals
变量销毁
重新赋值
unset()
常量
<?php
class Test
{
//the scope is this class
const NAME="100";
function classN()
{
//user without $
echo Test::NAME*312;
}
}
//the scope is global and it can be used anywhere
define("SITE_GLOBAL","www.site.com");
?>
魔术常量
name | Description |
---|---|
__LINE__ |
The current line number of the file. |
__FILE__ |
The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned. |
__DIR__ |
The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory. |
__FUNCTION__ |
The function name. |
__CLASS__ |
The class name. The class name includes the namespace it was declared in (e.g. Foo\Bar). Note that as of PHP 5.4 __CLASS__ works also in traits. When used in a trait method, __CLASS__ is the name of the class the trait is used in. |
__TRAIT__ |
The trait name. The trait name includes the namespace it was declared in (e.g. Foo\Bar). |
__METHOD__ |
The class method name. |
__NAMESPACE__ |
The name of the current namespace. |
特殊运算符
`: 反引号,相当于shell_exec()函数(安全模式只能使用函数),
<?php
echo `dir`;
?>
@:错误控制,放在表达式前,产生的错误被忽略。如果激活track_errors属性,错误存放在$php_errormsg变量中。
foreach
<?php
$season[0]='spring';
$season[1]='summer';
$season[2]='autumn';
$season[3]='winter';
foreach($season as $s)
{
echo $s,"<br>";
}
?>
PHP速学的更多相关文章
- Linux之:Ubuntu速学笔记(1)
撰写日期:2016-7-2 17:11:28 Saturday 课程资源: web程序员角度ubuntu自修速学课程 链接来源:程序员在囧途, VMware: VMware Workstation1 ...
- 沈逸老师ubuntu速学笔记(2)-- ubuntu16.04下 apache2.4和php7结合编译安装,并安裝PDOmysql扩展
1.编译安装apache2.4.20 第一步: ./configure --prefix=/usr/local/httpd --enable-so 第二步: make 第三步: sudo make i ...
- 沈逸老师ubuntu速学笔记(1)--安装flashplayer,配置中文输入法以及常用命令
开篇首先感谢程序员在囧途(www.jtthink.com)以及沈逸老师,此主题笔记主要来源于沈老师课程.同时也感谢少年郎,秦少.花旦等同学分享大家的学习笔记. 1.安装flash player ctr ...
- 快看Sample代码,速学Swift语言(1)-语法速览
Swift是苹果推出的一个比较新的语言,它除了借鉴语言如C#.Java等内容外,好像还采用了很多JavaScript脚本里面的一些脚本语法,用起来感觉非常棒,作为一个使用C#多年的技术控,对这种比较超 ...
- React Native之React速学教程(下)
概述 本篇为<React Native之React速学教程>的最后一篇.本篇将带着大家一起认识ES6,学习在开发中常用的一些ES6的新特性,以及ES6与ES5的区别,解决大家在学习Reac ...
- React Native之React速学教程(中)
概述 本篇为<React Native之React速学教程>的第一篇.本篇将从React的特点.如何使用React.JSX语法.组件(Component)以及组件的属性,状态等方面进行讲解 ...
- React Native之React速学教程(上)
概述 本篇为<React Native之React速学教程>的第一篇.本篇将从React的特点.如何使用React.JSX语法.组件(Component)以及组件的属性,状态等方面进行讲解 ...
- 突破,Objective-C开发速学手册
<突破,Objective-C开发速学手册> 基本信息 作者: 傅志辉 出版社:电子工业出版社 ISBN:9787121207426 上架时间:2013-7-12 出版日期:2013 年8 ...
- 快看Sample代码,速学Swift语言(2)-基础介绍 快看Sample代码,速学Swift语言(1)-语法速览
快看Sample代码,速学Swift语言(2)-基础介绍 Swift语言是一个新的编程语言,用于iOS, macOS, watchOS, 和 tvOS的开发,不过Swift很多部分内容,我们可以从C或 ...
- grpc之protobuf常用语法速学
1,语法速学(1):返回商品”数组”.repeated修饰符 Repeated:是一个修饰符,返回字段可以重复任意多次(包括0次) 可以认为就是一个数组(切片) 服务端: 创建protobuf文件 s ...
随机推荐
- Spring第四篇
在spring第三篇中介绍了bean元素属性 在第四篇中介绍spring注入的方式 1 set方法注入 建立一个User类 创建私有的属性 set get 方法 重写toString方法 代码如下 ...
- jmeter:dubbo接口测试
最近工作中接到一个需求,需要对一个MQ消息队列进行性能测试,测试其消费能力,开发提供了一个dubbo服务来供我调用发送消息. 这篇博客,介绍下如何利用jmeter来测试dubbo接口,并进行性能测试. ...
- 理解CNN中的通道 channel
在深度学习的算法学习中,都会提到 channels 这个概念.在一般的深度学习框架的 conv2d 中,如 tensorflow .mxnet ,channels 都是必填的一个参数. channel ...
- docker常用命令行集锦
对工作中用到的docker命令行进行一个汇总,方便以后的命令行查询,同时也为了加强记忆,会把工作中用到的命令,持续更新上 1.查看私有仓库都有哪些镜像 curl -X GET http://10.27 ...
- iOS工程师 - 简历
基本信息 姓 名:张学友 性 别:男 年 龄:28 学 历:本科 毕业学校:广西师范大学 专 业:通信工程 手 ...
- 算法训练 最大的算式(DP)
问题描述 题目很简单,给出N个数字,不改变它们的相对位置,在中间加入K个乘号和N-K-1个加号,(括号随便加)使最终结果尽量大.因为乘号和加号一共就是N-1个了,所以恰好每两个相邻数字之间都有一个符号 ...
- [SinGuLaRiTy] NOIP模拟赛(TSY)-Day 2
[SinGuLaRiTy-2033] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. ...
- 前端JS AES加密 后端PHP AES加解密
<!DOCTYPEhtml> <html> <head> <title>aes demo</title> </head> < ...
- Python 模拟简单区块链
首先这是说明一下这是Tiny熊老师的教程https://www.cnblogs.com/tinyxiong 另外还要说明一下,暑假指导老师让我们做一些关于区块链的应用.这里只是涉及极其简单的模拟,主要 ...
- 2017第八届蓝桥杯决赛(C++ B组)2.磁砖样式
磁砖样式 小明家的一面装饰墙原来是 310 的小方格. 现在手头有一批刚好能盖住2个小方格的长方形瓷砖. 瓷砖只有两种颜色:黄色和橙色. 小明想知道,对于这么简陋的原料,可以贴出多少种不同的花样来. ...