基本代码

<?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速学的更多相关文章

  1. Linux之:Ubuntu速学笔记(1)

    撰写日期:2016-7-2 17:11:28 Saturday 课程资源:  web程序员角度ubuntu自修速学课程 链接来源:程序员在囧途, VMware: VMware Workstation1 ...

  2. 沈逸老师ubuntu速学笔记(2)-- ubuntu16.04下 apache2.4和php7结合编译安装,并安裝PDOmysql扩展

    1.编译安装apache2.4.20 第一步: ./configure --prefix=/usr/local/httpd --enable-so 第二步: make 第三步: sudo make i ...

  3. 沈逸老师ubuntu速学笔记(1)--安装flashplayer,配置中文输入法以及常用命令

    开篇首先感谢程序员在囧途(www.jtthink.com)以及沈逸老师,此主题笔记主要来源于沈老师课程.同时也感谢少年郎,秦少.花旦等同学分享大家的学习笔记. 1.安装flash player ctr ...

  4. 快看Sample代码,速学Swift语言(1)-语法速览

    Swift是苹果推出的一个比较新的语言,它除了借鉴语言如C#.Java等内容外,好像还采用了很多JavaScript脚本里面的一些脚本语法,用起来感觉非常棒,作为一个使用C#多年的技术控,对这种比较超 ...

  5. React Native之React速学教程(下)

    概述 本篇为<React Native之React速学教程>的最后一篇.本篇将带着大家一起认识ES6,学习在开发中常用的一些ES6的新特性,以及ES6与ES5的区别,解决大家在学习Reac ...

  6. React Native之React速学教程(中)

    概述 本篇为<React Native之React速学教程>的第一篇.本篇将从React的特点.如何使用React.JSX语法.组件(Component)以及组件的属性,状态等方面进行讲解 ...

  7. React Native之React速学教程(上)

    概述 本篇为<React Native之React速学教程>的第一篇.本篇将从React的特点.如何使用React.JSX语法.组件(Component)以及组件的属性,状态等方面进行讲解 ...

  8. 突破,Objective-C开发速学手册

    <突破,Objective-C开发速学手册> 基本信息 作者: 傅志辉 出版社:电子工业出版社 ISBN:9787121207426 上架时间:2013-7-12 出版日期:2013 年8 ...

  9. 快看Sample代码,速学Swift语言(2)-基础介绍 快看Sample代码,速学Swift语言(1)-语法速览

    快看Sample代码,速学Swift语言(2)-基础介绍 Swift语言是一个新的编程语言,用于iOS, macOS, watchOS, 和 tvOS的开发,不过Swift很多部分内容,我们可以从C或 ...

  10. grpc之protobuf常用语法速学

    1,语法速学(1):返回商品”数组”.repeated修饰符 Repeated:是一个修饰符,返回字段可以重复任意多次(包括0次) 可以认为就是一个数组(切片) 服务端: 创建protobuf文件 s ...

随机推荐

  1. 数据结构_XingYunX(幸运儿)

    数据结构_XingYunX(幸运儿) 问题描述 泡泡最近下了个饱了吗 app,这个 app 推出了个坑蒙拐骗的红包系统,只要花一块钱买张一元抵用券,就有参与 20 元红包的抽奖机会,抽奖界面会实时显示 ...

  2. 20169219《Linux内核原理及分析》第十二周作业

    格式化字符串漏洞实验 格式化字符串攻击原理是利用格式化函数(如printf())的沿着堆栈指针向下打印的特性,通过只提供格式化字符串但不提供对应的变量,读取栈内空间的内容. 更进一步,通过将某个要攻击 ...

  3. Android ExpandableListView的使用

    一.MainActivity要继承ExpandableListActivity.效果是当单击ListView的子项是显示另一个ListView. package com.example.explear ...

  4. 《Linux内核设计与实现》读书笔记(六)- 内核数据结构

    内核数据结构贯穿于整个内核代码中,这里介绍4个基本的内核数据结构. 利用这4个基本的数据结构,可以在编写内核代码时节约大量时间. 主要内容: 链表 队列 映射 红黑树 1. 链表 链表是linux内核 ...

  5. JavaScript混淆压缩

    比较好用的压缩软件,支持合并 JsCompressor-v3.0 比较好用的混淆站点:http://dean.edwards.name/packer/

  6. 使用metasploit进行栈溢出攻击-2

    基本的栈溢出搞明白了,真实攻击中一个很重要的问题是shellcode生成. 利用Metasploit提供的工具,可以方便的生成shellcode,然后可以使用第一篇中的代码进行验证. 先说一下如何生成 ...

  7. ubuntu - mongoDB

    安装 - 官网 命令行安装后使用1 服务端 mongod -version @ 查看mongoDB sudo service mongod start 启动mongo服务 sudo service m ...

  8. poj2417(Baby-Step Giant-Step)

    题目链接:http://poj.org/problem?id=2417 题意:求满足给出 P, N, B, 求满足条件 BL == N (mod P) 的最小 L, 若不存在则输出 no soluti ...

  9. python3查询mysql数据

    python3不支持MySQLdb,代替的是import pymysql 连接数据库查表: import pymysqlconn= pymysql.connect( host='xx.xx.xx.xx ...

  10. Kbuild、Kconfig、make menuconfig、.config、Makefile之间的关系

    今天突发奇想,想在这里分享下比喻分析Kbuild ---->去饭店吃饭的过程.   1.Kconfig --->饭店的菜单 2.条件编译选项--->菜单中的每一盘菜,可以选择这个菜的 ...