SplObjectStorage::serialize()函数是PHP中的一个内置函数,用于序列化存储结果。
用法:
string SplObjectStorage::serialize()
参数:该函数不接受任何参数。
返回值:此函数返回一个字符串,该字符串表示存储。
以下程序说明了PHP中的SplObjectStorage::serialize()函数:
示例1:
<?php
// Create new storage class
$str = new SplObjectStorage;
$obj = new StdClass;
$str->attach($obj, "GeeksforGeeks");
// Print serialize result
echo $str->serialize();
?>
输出:
x:i:1;O:8:"stdClass":0:{}, s:13:"GeeksforGeeks";;m:a:0:{}
示例2:
<?php
$obj1 = new StdClass;
$obj2 = new StdClass;
// Create new storage class
$gfg1 = new SplObjectStorage();
$gfg1[$obj1] = "Geeks";
// Create new storage class
$gfg2 = new SplObjectStorage();
$gfg2[$obj1] = "GFG";
$gfg2[$obj2] = "GeeksClasses";
print_r( $gfg1->serialize(). "\n");
echo( $gfg2->serialize()."\n");
?>
输出:
x:i:1;O:8:"stdClass":0:{}, s:5:"Geeks";;m:a:0:{} x:i:2;O:8:"stdClass":0:{}, s:3:"GFG";;O:8:"stdClass":0:{}, s:12:"GeeksClasses";;m:a:0:{}
参考: https://www.php.net/manual/en/splobjectstorage.serialize.php
相关用法
- PHP SplObjectStorage next()用法及代码示例
- PHP SplObjectStorage contains()用法及代码示例
- PHP SplObjectStorage key()用法及代码示例
- PHP ArrayObject serialize()用法及代码示例
- PHP SplDoublyLinkedList serialize()用法及代码示例
- PHP ArrayIterator serialize()用法及代码示例
- PHP SplObjectStorage removeAllExcept()用法及代码示例
- PHP SplObjectStorage removeAll()用法及代码示例
- PHP SplObjectStorage offsetUnset()用法及代码示例
- PHP SplObjectStorage offsetSet()用法及代码示例
- PHP SplObjectStorage offsetGet()用法及代码示例
- PHP SplObjectStorage rewind()用法及代码示例
- PHP SplObjectStorage setInfo()用法及代码示例
- PHP SplObjectStorage unserialize()用法及代码示例
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | SplObjectStorage serialize() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。