您好,登錄后才能下訂單哦!
<?php /** * Created by PhpStorm. * User: zrj * Date: 18-4-24 * Time: 下午8:37 */ class Person { public $name; public function __construct(string $name) { $this->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 "<br/>"; //判斷指定的對象是否在存儲空間中 echo "是否包含指定對象:"; var_dump($container->contains($lisi)); echo "<br/>"; //從存儲中刪除指定對象 echo "刪除指定對象"; $container->detach($wangwu); //查看當前指針所在的索引位置 echo "指針索引" . $container->key(); echo "<br/>"; //重置存儲空間指針 $container->rewind(); //校驗當前指針是否有效 var_dump($container->valid()); //遍歷存儲空間 echo "<pre>"; while ($container->valid()) { //獲取當前指針位置的對象 var_dump($container->current()); //存儲空間指針下移 $container->next(); }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。