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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。