EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

PHP Serialize

Home » Software Development » Software Development Tutorials » PHP Tutorial » PHP Serialize

PHP Serialize

Introduction to PHP Serialize

The serialize is a function used in the PHP for changing the format of the value and making the value to be stored in a variable. The serialize value means a bit the collection of such a bit is called a serialize data. This function transforms the bit in such a way that the bits can be stored in the memory buffer. The serialize function plays a key role in transforming the value to the bits and makes them easy to be stored in the memory. The version which we use for this function is generally PHP4.

Syntax

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The syntax for the serialize() is:

serialize(variable1)

How does Serialize work in PHP?

Suppose we want to store the string values in the memory they have to get changed in such a way that they can be stored in memory. For that we use the serialize function. First assign the string values in a array to the variable named as serialized value use the function serialize().Then print the output using the print.

Examples to Implement PHP Serialize

Below are the examples to implement Serialize() in PHP

Example #1

Code:

<?php
$serialized_value = serialize(array ('Dell', 'Laptop', 'Good'));
echo $serialized_value;
?>

Output: Here s is the letter which counts the number of letters of the string according to it the bits are allocated in memory. i letter is the location of the string in the memory.

String

Explanation: As we already know that if we want to store some array of strings in a variable it must be in a format according to the format of the bits. To change the variable  which contains a array of strings into a storable format we use the serialize function which converts the variable values into bits and stored in the memory and at the end we can retrieve the output value back using the echo. The above example can be used to explain the serialize function. Here first we assign an array of strings to the variable serialize value.

Code:

$serialized_value = serialize(array ('Dell', 'Laptop', 'Good'));

  • The serialize function coverts them into bits and stores into memory.
  • The output can be displayed using the following command

echo $serialized_value;

  • echo is used to display the output

Example #2

Code:

<?php
$variable1 = array ('Monday',  100,array(2, 'three'),  'February');
$variable2 = serialize($variable1);
echo $variable2;
?>

Output: Here s is the letter used to count the number of bit stored in the memory and I is the location allocated to the memory.

PHP2

Explanation: Here we have taken a different data types of values stored in a variable.to convert them into a format suitable to store in a memory we use the serialize function. It converts the values into the bits and allocates the location in memory for storing the values. First  we assign the array of strings and numbers into the variable1.

Code:

$variable1 = array (‘Monday',  100,array(2, 'three'),  'February’);

Code: Next, we convert the variable 1 into the format suitable to store bits into memory we use serialize function as shown below.

$variable2= serialize($variable1);

  • Next to print the output we use echo keyword.

echo $variable2;

Example #3

Code:

<?php
$a1 = serialize (array ("Monday", "Tuesday", "Wednesday"));
$a2 = serialize (array ("good", "bad", "happy"));
$a3 = serialize (array ("University", "fellow"));
echo $a1;
echo $a2;
echo $a3;
?>

Output: Here s is the letter which stores bits in the memory, and I letter allocates the location of the strings.

Popular Course in this category
PHP Training (5 Courses, 3 Project)5 Online Courses | 3 Hands-on Project | 28+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,694 ratings)
Course Price

View Course

Related Courses
Java Servlet Training (6 Courses, 12 Projects)All in One Software Development Bundle (600+ Courses, 50+ projects)

serialize function

Explanation: Here we want to store the strings in the memory and display them. So first we allocate the different strings in a array to the different variables like a1,a2,a3.Then we use the serialize function to convert the values into bits and store them in the memory for that we use the serialize function. The values are allocated as shown below.

Code:

$a1 = serialize (array ("Monday", "Tuesday", "Wednesday"));
$a2 = serialize (array ("good", "bad", "happy"));
$a3 = serialize (array ("University", "fellow"));

  • Then we display the output using the echo which is shown below

echo $a1;
echo $a2;
echo $a3;

Conclusion

The PHP is easy to install. The PHP is dynamic. The serialize function is used to change the format of the variable and make it suitable for storing it in the memory. Here the letter s is used to count the number of bits stored in the memory and I is used to memory location for storing the value. The code is written in the script format and the output is displayed in the web browser. Easy to understand. There are 8 data types. There are 5 different types of operators.

Recommended Articles

This is a guide to PHP Serialize. Here we discuss the introduction to PHP Serialize, along with its working, appropriate syntax and respective examples. You can also go through our other related articles to learn more –

  1. PHP Frameworks
  2. PHP References
  3. PHP Log Errors
  4. PHP Array Search

All in One Software Development Bundle (600+ Courses, 50+ projects)

600+ Online Courses

50+ projects

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PHP Tutorial
  • Functions
    • Functions in PHP
    • PHP Math Functions
    • PHP Recursive Function
    • PHP String Functions
    • Hashing Function in PHP
    • Date Function in PHP
    • PHP Anonymous Function
    • Calendar in PHP
    • PHP Call Function
    • PHP Pass by Reference
    • PHP ucfirst()
    • PHP ucwords()
    • trim() in PHP
    • isset() Function in PHP
    • PHP replace
    • PHP fpm
    • PHP strpos
    • preg_match in PHP
    • PHP preg_replace()
    • PHP ob_start()
    • PHP Reflection
    • PHP Split String
    • PHP URL
    • PHP preg_match_all
    • PHP strtoupper()
    • PHP preg_split()
    • PHP substr_replace()
    • PHP setlocale()
    • PHP substr_count()
    • PHP Serialize
    • PHP strlen()
    • PHP async
    • PHP Date Time Functions
    • PHP timezone
    • PHP Data Object
    • print_r() in PHP
    • PHP header()
    • PHP strip_tags()
    • PHP chop()
    • PHP MD5()
    • PHP unset()
    • PHP crypt()
    • PHP wordwrap()
    • PHP is_null()
    • PHP strtok()
    • PHP bin2hex()
    • PHP parse_str()
    • PHP levenshtein()
    • PHP addslashes()
    • PHP strtotime
    • PHP sha1()
    • PHP explode()
    • PHP sscanf()
    • PHP require_once
    • PHP Zip Files
    • PHP $_SERVER
    • PHP $_POST
    • PHP Include and Require
    • PHP POST Method
  • PHP Basic
    • Introduction To PHP
    • What is PHP
    • PHP Keywords
    • Advantages of PHP
    • Career In PHP
    • Comments in PHP
    • PHP Commands
    • PHP Frameworks
    • PHP Compiler
    • Variables in PHP
    • PHP Superglobal Variables
    • PHP Versions
    • Object in PHP
    • What is Drupal
    • Top PHP Frameworks
    • WebStorm IDE
    • What is phpMyAdmin?
    • PhpStorm
    • Install phpMyAdmin
    • Phalcon Model
  • Data Types
    • PHP Data Types
    • PHP Integer
    • PHP Booleans
  • Operators
    • PHP Operators
    • Arithmetic Operators in PHP
    • Comparison Operators in PHP
    • Logical Operators in PHP
    • Bitwise Operators in PHP
    • Ternary Operator in PHP
    • PHP String Operators
  • Control Statements
    • Control Statement in PHP
    • PHP if Statement
    • if else Statement in PHP
    • elseif in PHP
    • PHP Switch Statement
    • Continue in PHP
    • Break in PHP
  • Loops
    • PHP Loops
    • For Loop in PHP
    • PHP Do While Loop
    • PHP While Loop
    • While Loop in PHP
    • Foreach Loop in PHP
  • Constructor
    • Constructor in PHP
    • Destructor in PHP
  • State Management
    • Cookie in PHP
    • Sessions in PHP
  • Array
    • What is PHP Array
    • Arrays in PHP
    • 2D Arrays in PHP
    • Associative Array in PHP 
    • Multidimensional Array in PHP
    • Indexed Array in PHP
    • PHP Array Functions
    • PHP unset Array
    • PHP Append Array
    • PHP Array Search
    • PHP Split Array
    • PHP array_push()
    • PHP array_pop()
  • Advanced
    • Overloading in PHP
    • Overriding in PHP
    • Method Overloading in PHP
    • Inheritance in PHP
    • Multiple Inheritance in PHP
    • PHP Interface
    • Encapsulation in PHP
    • PHP Constants
    • PHP Magic Constants
    • PHP Regular Expressions
    • PHP GET Method
    • PHP Annotations
    • PHP Encryption
    • PHP file Functions
    • PHP readfile
    • PHP?Write File
    • PHP Append File
    • PHP Type Hinting
    • PHP Filters
    • PHP Float
    • PHP Form
    • PHP Form Validation
    • Sorting in PHP
    • PHP usort()
    • PHP Stack Trace
    • PHP Stack Overflow
    • PHP Pagination
    • PHP implode
    • Polymorphism in PHP
    • Abstract Class in PHP
    • PHP Final Class
    • PHP Custom Exception
    • error_reporting() in PHP
    • PHP Log Errors
    • Access Modifiers in PHP
    • PHP Change Date Format
    • Static Method in PHP
    • PHP File Handling
    • PHP Output Buffering
    • Get IP Address in PHP
    • Upload a File in PHP
    • String in PHP
    • Public Function in PHP
    • Private in PHP
    • Protected in PHP
    • basename in PHP
    • Validation in PHP
    • PHP mail()
    • PHP Email Form
    • PHP Directory
    • PHP Create Session
    • PHP include_once
    • PHP json_decode
    • PHP XMLWriter
    • PHP XML Reader
    • PHP XML Parser
    • PHP XML into Array
    • Phalcon Framework
  • Programs
    • Patterns in PHP
    • Star Patterns in PHP
    • Swapping in PHP
    • Fibonacci Series PHP
    • Factorial in PHP
    • Reverse String in PHP
    • Square Root in PHP
    • Random Number Generator in PHP
    • Palindrome in PHP
    • Prime Numbers in PHP
    • Armstrong Number in PHP
    • Socket Programming in PHP
    • Login Page in PHP
    • PHP Login Template
    • PHP Object to String
  • Database
    • PHP Database Connection
    • How to Connect Database to PHP
  • Interview Questions
    • PHP Interview Questions
    • PHP OOP Interview Questions
    • CakePHP Interview Questions
    • Core PHP Interview Questions

Related Courses

PHP Training Course

Java Servlet Training

Software Development Course Training

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - PHP Training Course Learn More