Wednesday, June 17, 2026
HomeLanguagesPHP | ArrayIterator serialize() Function

PHP | ArrayIterator serialize() Function

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);
  
?>


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
     
// 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);
     
?>


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

RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS