PHP | ArrayIterator serialize() Function
Last Updated :
21 Nov, 2019
The ArrayIterator::serialize() function is an inbuilt function in PHP which is used to serialize the array iterator.
Syntax:
string ArrayIterator::serialize( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns the serialized ArrayIterator.
Below programs illustrate the ArrayIterator::serialize() function in PHP:
Program 1:
<?php
$arrItr = new ArrayIterator(
array ( 'G' , 'e' , 'e' , 'k' , 's' )
);
$serialize = $arrItr ->serialize();
var_dump( $serialize );
?>
|
Output:
string(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:{}”
Program 2:
<?php
$arrItr = new ArrayIterator(
array (
"a" => "Geeks" ,
"b" => "for" ,
"c" => "Geeks"
)
);
$arrItr ->append( "Computer" );
$arrItr ->append( "Science" );
$arrItr ->append( "Portal" );
$serialize = $arrItr ->serialize();
var_dump( $serialize );
?>
|
Output:
string(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:{}”
Reference: https://www.php.net/manual/en/arrayiterator.serialize.php
Share your thoughts in the comments
Please Login to comment...