十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
name = $name; } } //实例化对象 $zhangsan = new Person('张三'); $lisi = new Person('李四'); $wangwu = new Person('王五'); $zhaoliu = new Person('赵六'); //实例化对象存储 $container = new SplObjectStorage(); //往存储空间写入对象 $container->attach($zhangsan); $container->attach($lisi); $container->attach($wangwu); $container->attach($zhaoliu); //统计存储空间里面的对象的数量 echo "存储对象数量" . $container->count(); echo "
"; //判断指定的对象是否在存储空间中 echo "是否包含指定对象:"; var_dump($container->contains($lisi)); echo "
"; //从存储中删除指定对象 echo "删除指定对象"; $container->detach($wangwu); //查看当前指针所在的索引位置 echo "指针索引" . $container->key(); echo "
"; //重置存储空间指针 $container->rewind(); //校验当前指针是否有效 var_dump($container->valid()); //遍历存储空间 echo ""; while ($container->valid()) { //获取当前指针位置的对象 var_dump($container->current()); //存储空间指针下移 $container->next(); }
本文名称:SPL之SplObjectStorage对象存储
当前地址:http://6mz.cn/article/pdscgd.html