php.js : serialize() function

serialize() function

The serialize() function is used to get a string representation of a variable.






Name Description Required /
value1 The value to be serialized Required Mixed*

*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Example of php.js serialize() function:

In the following web document, serialize() function serialize an array.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>php.js : serialize() function example</title>
<script type="text/javascript" src="../../phpjs/variable/variable.min.js"> </script>
<h1 style="color: green">php.js : serialize() function example</h1>
<h3>A string representation of variable...</h3>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
document.write('Original Array : '+" Array('Math', 'Language', 'Science')"+'<br />')
document.write("After serialized ; " +serialize(Array('Math', 'Language', 'Science')));

Output of the function:

Original Array:  Array('Math', 'Language', 'Science')
After serialized ; a:3:{i:0;s:4:"Math";i:1;s:8:"Language";i:2;s:7:"Science";} 

View example of php.js serialize() function in browser

Download phpjs.zip

Previous: php.js : print_r() function
Next: php.js : settype() function

Follow us on Facebook and Twitter for latest update.

We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook