目录
1.类和对象
<?php
//类
class cl {
var $name = "fly"; // 类属性
//函数
function _destruct(){
echo $this->name;
}
//函数
function eat() {
echo 'apple';
}
}
//对象
$a = new cl();
echo $a->name.'<br>'; //直接调用类里的属性
echo $a->eat().'<br>';//直接调用类里的函数
?>
2.序列化
序列化,将其他的数据转换成字符串<?php $a = array("one", 23, "apple", "three"); //序列化 $b = serialize($a); var_dump($a); echo '<br>'; echo $b.'<br>'; ?>
打印效果
array(4) { [0]=> string(3) "one" [1]=> int(23) [2]=> string(5) "apple" [3]=> string(5) "three" }
a:4:{i:0;s:3:"one";i:1;i:23;i:2;s:5:"apple";i:3;s:5:"three";}
3.反序列化
将序列化的字符串还原成原来的数据类型<?php $a = array("one", 23, "apple", "three"); //序列化 $b = serialize($a); var_dump($a); echo '<br>'; echo $b.'<br>'; //反序列化 $c = unserialize($b); var_dump($c); ?>
打印效果
array(4) { [0]=> string(3) "one" [1]=> int(23) [2]=> string(5) "apple" [3]=> string(5) "three" }
a:4:{i:0;s:3:"one";i:1;i:23;i:2;s:5:"apple";i:3;s:5:"three";}
array(4) { [0]=> string(3) "one" [1]=> int(23) [2]=> string(5) "apple" [3]=> string(5) "three" }