$开头的是变量,变量的值还能当变量名,真好!这让我怀念起了LOGO ——我接触的第一门语言,语法跟汇编差不多。
<?php

$var_name='_next';
$_next='Variable: next';
echo $$var_name."<br>"; # $var_name的值是_next,所以这里$$var_name相当于$_next
echo "$$var_name <br>"; # 这里$$代表单独一个$,就好像Makefile一样

# consts
define('E',2.718); # 定义常量
echo E.'<br>'; # 常量前边不加$

# 数据类型:integer, float, string, boolean, array, object
# 类型转换
$str_E=(string)E;
echo $str_E.'<br>';

# operators
# number: +-*/% ++ -- += -= *= /= %=
# string: . .=
# assignment: = (跟C一样返回自己)
$str_conn="abc";
$str_conn.='def';
echo "$str_conn<br>";
# 赋值时先产生一个副本,然后再保存到目标去
# reference & <-- not a pointer, just a alias
$ref=&$str_conn;
$str_conn='ghi';
echo "$ref<br>";
unset($ref); # 解除引用
$ref="ref";
echo "$ref, $str_conn<br>";

# compare: ==/!= ===/!== <> < > <= >=
# == 值相等 , !=
$result=0=='0'?"true":"false"; // true
echo "$result<br>";
# === 值相等,数据类型相同 , !==
$result=0==='0'?"true":"false"; // false
echo "$result<br>";
# <> 不等
$result=0<>'0'?"true":"false"; // false
echo "$result<br>";

# logical operators
# ! && || , and or
# &&=and, ||=or, 不过and和or的优先级比较低,
# 注意,or,xor,and,print的优先级比=还要低
# =>print>and>xor>or>,

# bitwise operators
# & | ~ ^(xor) << >>

# other operators
# , ?:
# 错误抑制操作符 @
$a=@(50/0); // 不加的话将有除0警告,如果启用了php的track_errors属性,错误信息将会被保存在全局
// 变量$php_errormsg中
echo $a;

# `` 执行shell命令
$a=`dir c:/`;
echo "<pre>";
echo "$a";
echo "</pre>";

# array operators
# + ==(相同元素) ===(元素相同,顺序相同) != <> !==

# instanceof
class sampleClass{};
$myObject=new sampleClass();
if ( $myObject instanceof sampleClass )
echo "myObject is an instance of sampleClass<br>";
else echo "myObject is not an instance of sampleClass<br>";

# gettype() settype()
$a=56;
echo gettype($a)."<br>";
settype($a,"float");
echo gettype($a)." ".$a."<br>";
# is_array()
# is_double(), is_float(), is_real <-- they are the same
# is_long(), is_int(), is_integer() <-- they are the same
# is_string()
# is_object()
# is_resource() resource和外部类型,null是一种特殊的类型,值是NULL
# is_null()
# is_scalar() 是否标量(integer, float, boolean, string)
# is_numberic()
# is_callable() 是否有效的函数名称

# isset()
# empty()看是否为非空或者非0
if (isset($b)) {
echo "b is set<Br>";
} else {
echo "b isn't set<br>";
}
if (isset($a)) {
echo "a is set<Br>";
} else {
echo "a isn't set<br>";
}

# int intval() // 类型转换
# float floatval()
# string strval()
?>











































































































