ArrayIterator::unserialize()函數是PHP中的一個內置函數,用於反序列化序列化對象。
用法:
void ArrayIterator::unserialize( string $serialized )
參數:此函數接受單個參數$serialized,該參數保存序列化數組迭代器對象。
返回值:此函數返回未序列化對象的序列化ArrayIterator對象。
以下示例程序旨在說明PHP中的ArrayIterator::unserialize()函數:
程序1:
<?php
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
array('G', 'e', 'e', 'k', 's')
);
// Serialize the element
$serialize = serialize($arrItr);
// Display the output
var_dump($serialize);
// Unserialize the serialize element
$unserialize = unserialize($serialize);
// Display the result
var_dump($unserialize);
?>
輸出:
string(107) "C:13:"ArrayIterator":81:{x:i:0;a:5:{i:0;s:1:"G";i:1; s:1:"e";i:2;s:1:"e";i:3;s:1:"k";i:4;s:1:"s";};m:a:0:{}}" object(ArrayIterator)#2 (1) { ["storage":"ArrayIterator":private]=> array(5) { [0]=> string(1) "G" [1]=> string(1) "e" [2]=> string(1) "e" [3]=> string(1) "k" [4]=> string(1) "s" } }
程序2:
<?php
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
array(
"a" => "Geeks",
"b" => "for",
"c" => "Geeks"
)
);
// Append some elements
$arrItr->append("Computer");
$arrItr->append("Science");
$arrItr->append("Portal");
// Serialize the element
$serialize = serialize($arrItr);
// Display the output
var_dump($serialize);
// Unserialize the element
$unserialize = unserialize($serialize);
// Display the output
var_dump($unserialize);
?>
輸出:
string(160) "C:13:"ArrayIterator":133:{x:i:0;a:6:{s:1:"a";s:5:"Geeks"; s:1:"b";s:3:"for";s:1:"c";s:5:"Geeks";i:0;s:8:"Computer";i:1; s:7:"Science";i:2;s:6:"Portal";};m:a:0:{}}" object(ArrayIterator)#2 (1) { ["storage":"ArrayIterator":private]=> array(6) { ["a"]=> string(5) "Geeks" ["b"]=> string(3) "for" ["c"]=> string(5) "Geeks" [0]=> string(8) "Computer" [1]=> string(7) "Science" [2]=> string(6) "Portal" } }
參考: https://www.php.net/manual/en/arrayiterator.unserialize.php
相關用法
- PHP SplObjectStorage unserialize()用法及代碼示例
- PHP SplDoublyLinkedList unserialize()用法及代碼示例
- PHP ArrayObject unserialize()用法及代碼示例
- PHP ArrayIterator next()用法及代碼示例
- PHP ArrayIterator key()用法及代碼示例
- PHP ArrayIterator asort()用法及代碼示例
- PHP ArrayIterator __construct()用法及代碼示例
- PHP ArrayIterator append()用法及代碼示例
- PHP ArrayIterator seek()用法及代碼示例
- PHP ArrayIterator seek()用法及代碼示例
- PHP ArrayIterator valid()用法及代碼示例
- PHP ArrayIterator rewind()用法及代碼示例
- PHP ArrayIterator offsetSet()用法及代碼示例
- PHP ArrayIterator offsetGet()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | ArrayIterator unserialize() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。