时间:2021-07-01 10:21:17 帮助过:6人阅读
1.时间和日期
echo time();
echo date('Y-m-d H:i:s');
echo date_default_timezone_get();
date_default_timezone_set('Asia/Shanghai'); //设置为上海的时区echo date('Y-m-d H:i:s');
echo date('Y-m-d H:i:s',time());echo '
';echo date('Y-m-d H:i:s',time());
2.JSON格式数据的操作
数组可以嵌套(数组中包含数组)
还可以包含对象(内部数据的值和名字相对应,键值对)
[1,2,5,7,8,"Hello",[6,7,8],{"h","Hello"}]
{"h":"Hello","w":"World",[1,2,3]}
$arr = array(1,2,5,8,"Hello","CQUT",array("h"=>"Hello","name"=>"CQUT"));echo 'array format => '.'
';print_r($arr);echo '
';echo 'json formate =>'.'
';echo json_encode($arr);//json_encode将一个对象转成json格式的数据
输出
array format =>
Array ( [0] => 1 [1] => 2 [2] => 5 [3] => 8 [4] => Hello [5] => CQUT [6] => Array ( [h] => Hello [name] => CQUT ) )
json formate =>
[1,2,5,8,"Hello","CQUT",{"h":"Hello","name":"CQUT"}]
$obj = array('h'=>'Hello','w'=>'World',array(1,2,3));echo json_encode($obj);
输出
{"h":"Hello","w":"World","0":[1,2,3]}
$jsonStr = '{"h":"Hello","w":"World","0":[1,2,3]}';$obj = json_decode($jsonStr);print_r($obj);echo '
';echo $obj->h;
输出
stdClass Object ( [h] => Hello [w] => World [0] => Array ( [0] => 1 [1] => 2 [2] => 3 ) )
Hello