Friday, October 24, 2025
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
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS