當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP SplObjectStorage unserialize()用法及代碼示例


SplObjectStorage::unserialize()函數是PHP中的內置函數,用於從其序列化字符串表示形式反序列化存儲。

用法:

void SplObjectStorage::unserialize( $serilize )

參數:該函數接受單個參數$serialize,該參數指定存儲的字符串序列化。


返回值:該函數不返回任何值。

以下程序說明了PHP中的SplObjectStorage::unserialize()函數:

程序1:

<?php 
  
$obj1 = new StdClass; 
  
// Create an empty SplObjectStorage 
$gfg1 = new SplObjectStorage(); 
$gfg1[$obj1] = "Geeks"; 
  
// Use unserialize() function 
$gfg1->unserialize($gfg1->serialize()); 
print_r($gfg1); 
  
?>
輸出:
SplObjectStorage Object
(
    [storage:SplObjectStorage:private] => Array
        (
            [00000000494fcd4d000000001f544823] => Array
                (
                    [obj] => stdClass Object
                        (
                        )

                    [inf] => Geeks
                )

            [00000000494fcd4f000000001f544823] => Array
                (
                    [obj] => stdClass Object
                        (
                        )

                    [inf] => Geeks
                )

        )

)

程序2:

<?php 
  
$obj1 = new StdClass; 
$obj2 = new StdClass; 
  
// Create an empty SplObjectStorage 
$gfg1 = new SplObjectStorage(); 
$gfg1[$obj1] = "Geeks"; 
  
// Create an empty SplObjectStorage 
$gfg2 = new SplObjectStorage(); 
$gfg2[$obj1] = "GFG"; 
$gfg2[$obj2] = "GeeksClasses"; 
  
// Use unserialize() function 
$gfg1->unserialize($gfg2->serialize()); 
var_dump(count($gfg1)); 
  
// Use unserialize() function 
$gfg2->unserialize($gfg1->serialize()); 
var_dump(count($gfg2)); 
?>
輸出:
int(3)
int(5)

參考: https://www.php.net/manual/en/splobjectstorage.unserialize.php



相關用法


注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | SplObjectStorage unserialize() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。