PHP的基本常识小结
前端之家收集整理的这篇文章主要介绍了
PHP的基本常识小结,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@这些PHP的概念,有些刚开始比较难懂,很难理解,我把他们都列出来,希望能帮助一些人,在前进的路上少点荆棘。
@H_
5020@1. variable variables(变量的变量)
@H502_0@variable_variables.
PHP
@H_
502_0@<div class="codetitle">
<a style="CURSOR: pointer" data="61831" class="copybut" id="copybut61831" onclick="doCopy('code61831')"> 代码如下: <div class="codebody" id="code61831">
<?
PHP$a = 'hello';
$hello = 'hello everyone';
@H_
5020@echo $$a.'
';
@H5020@$b = 'John';
$c = 'Mary';
$e = 'Joe';
@H5020@$students = array('b','c','e');
@H5020@echo ${$students[1]};
/
foreach($students as $seat){
echo $$seat.'
';
}
$$var[1]
${$var[1]} for #1
/
@H
5020@$a = 'hello';
@H5020@将hello 赋值给 变量 $a,于是 $$a = ${hello} = $hello = 'hello everyone';
@H502_0@如果对于 $$students[1],这样会产生混乱,
PHP的解释器可能无法理解,‘[' 虽然有较高运算符,但结果可能无法
输出。
@H_
5020@好的写法是:${$students[1]} = ‘Mary';
@H502_0@
2. array's function(数组函数)
@H_
502_0@array_functions.
PHP
@H_
502_0@<div class="codetitle">
<a style="CURSOR: pointer" data="53545" class="copybut" id="copybut53545" onclick="doCopy('code53545')"> 代码如下: <div class="codebody" id="code53545">
<?
PHPecho '
shift & unshift
';
$numbers = array(1,2,3,4,5,6);
print
r($numbers);
echo '
';
@H502_0@// shifts first elemnt out of an array
// the index will reset
$a = array
shift($numbers);
@H502_0@echo 'a: '.$a.'
';
print
r($numbers);
@H502_0@// push element to the front of array
// returns the count of array and reset array index
$b = array_unshift($numbers,'first');
echo '
b: '.$b.'
';
print
r($numbers);
@H502_0@echo '
';
echo '
pop & push
';
// pop the last element out of array
$c = array_pop($numbers);
print
r($numbers);
echo '
';
@H502_0@// push the element to the last of array
$d = array
push($numbers,'last');
echo 'd: '.$d.'
';
@H502_0@print
r($numbers);
@H
502_0@
更多数组函数参考
@H_
502_0@
3. dates and times (时间和日期)
有3种
方法可以创建一个unix time(从1970/1/1 到现在的秒数) time(); 返回当前的时间戳 mktime($hr,$min,$sec,$month,$day,$year); mktime(6,30,22,2012) 返回2012 5/22 6:30:00 的时间戳 strtotime($string); strtotime("+1 day") 返回明天这个时候的时间戳 更多 'last Monday' 'lasy Year' checkdate($month,$year); 验证一个日期是否为真 checkdate(5,32,2012) ? 'true' : 'false'; // return false 得到了时间戳后,我们需要对它进行转化为可读的,如2012/5/22 我们有2种
方法 date($format,$timestamp) ; strftime($format [,$timestamp]) 推荐用第2种,strftime("%Y-%m-%d %H:%M:%S"); // return 2012-05-22 15:46:40
@H_
502_0@
更多时间日期参考
@H_
502_0@
5. server variables (服务器和执行环境信息)
$_SERVER server_variables.
PHP <div class="codetitle">
<a style="CURSOR: pointer" data="31519" class="copybut" id="copybut31519" onclick="doCopy('code31519')"> 代码如下: