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 // Declare an ArrayIterator $arrItr = new ArrayIterator( array ( 'G' , 'e' , 'e' , 'k' , 's' ) ); // Serialize the element $serialize = $arrItr ->serialize(); // Display the output var_dump( $serialize ); ?> |
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 // 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 = $arrItr ->serialize(); // Display the output var_dump( $serialize ); ?> |
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