Web Distributed Data Exchange Step By Step tutorial - Part 8: Now, we try to serialize data use PHP's function. PHP have 2 function to serialize data into WDDX packet, wddx_serialize_value() wddx_serialize_vars(). these functions create a complete WDDX packet using just single line. oke, look following sample:
<?
$arrNum = array(1,2,3);
print wddx_serialize_value($arrNum, "This is my first wddx packet");
?>
The result is like this:
<wddxPacket version='1.0'>
<header>
<comment>This is my first wddx packet</comment>
</header>
<data>
<array length='3'>
<number>1</number>
<number>2</number>
<number>3</number>
</array>
</data>
</wddxPacket>
Another option to serialize data using wddx_serialize_vars(). We can put more than one variabel in this function, but we can not put header. This is example:
<?php
$arrNum = array(1,2,3);
$arrStr = array('PHP Undercover','Wiwit Siswoutomo');
$arr = array($arrNum, $arrStr);
print wddx_serialize_vars('arrNum','arrStr','arr');
?>
The result:
<wddxPacket version='1.0'>
<header/>
<data>
<struct>
<var name='arrNum'>
<array length='3'>
<number>1</number>
<number>2</number>
<number>3</number>
</array>
</var>
<var name='arrStr'>
<array length='2'>
<string>PHP Undercover</string>
<string>Wiwit Siswoutomo</string>
</array>
</var>
<var name='arr'>
<array length='2'>
<array length='3'>
<number>1</number>
<number>2</number>
<number>3</number>
</array>
<array length='2'>
<string>PHP Undercover</string>
<string>Wiwit Siswoutomo</string>
</array>
</array>
</var>
</struct>
</data>
</wddxPacket>