PHP_EOL:
代表php的换行符,这个变量会根据平台而变,在windows下会是/r/n,在linux下是/n,在mac下是/r;
<?php
$test = 'string from mark';
$username = isset($test) ? $test : 'nobody';
echo $username, PHP_EOL;
switch statement: 避免if语句过于冗长,提高程序可读性;
<?php
$favcolor = 'red';
switch ($favcolor) {
case 'red':
echo 'Your favorite color is red!';
break;
case 'blue':
echo 'Your favorite color is blue!';
break;
case 'green':
echo 'Your favorite color is green!';
break;
default:
echo 'Your favorite color is neither red, blue, or green!';
}
array:
- 数值数组: array with index;
- 关联数据: array with key (actually dictionry);
- 多维数据: contains 1+ array as elements;
<?php
$cars = array("Volvo", "BMW", "Toyota");
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
超级全局变量
变量名 | 作用 |
---|---|
$GLOBALS | |
$_SERVER | |
$_REQUEST | |
$_POST | |
$_GET | |
$_FILES | |
$_ENV | |
$_COOKIE | |
$_SESSION |