PHP serialize()

📔 : PHP 🔗

serialize() function किसी value को storable form में convert करता है , इस process को serialization कहते हैं।


What is serialization

serialization एक ऐसी process है जिसमे किसी Data Structure या Object को Byte Stream में convert करना जिससे उसे किसी storage (जैसे file or memory data buffer) में store किया जा सके या किसी network पर send किया जा सके।


PHP में serialize() function , data के type और structure में changes किये बिना store करने के लिए बहुत useful है।

PHP serialize Syntax

serialize( mixed $value );
Parameters
  1. mixed $value | required : variable जिसे आपको serialized करना है।

  2. Return Value : एक string return होती है जो की pass की गयी value का byte-stream representation होता है , जिसे आप कहीं भी store / transmit कर सकते हैं।


PHP serialize Example

<?php
  $var = ['name' => 'rahul Kumar', 'age' => 24, 'marriage'=> false];
  echo serialize($var);
?> 

Output
a:3:{s:4:"name";s:11:"rahul Kumar";s:3:"age";i:24;s:8:"marriage";b:0;}

data serialized होने के बाद कुछ इस तरह से convert होता है। serialized String में आपको हर value के बारे में complete info मिलेगी जैसे (data type , length etc. ).


Example में एक Associative Array को serialized किया गया है। Output में आप देख सकते हैं किसी तरह से value के साथ - साथ key के type और length को manage किया गया है।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook