Menu
Hi,
Can any one tell me about php serialize and unserialize function with example? How these function work with forms array fields? If i want to post multi-dementional array data how i post these values?…
Waiting for any good response…………
[code=php]print_r($_POST['first']);[/code]
[code=php]
<?php
$first = $_POST["first"];
$last = $_POST["last"];
$age = $_POST["age"];
$ser_first2 = serialize($first);
$ser_last2 = serialize($last);
$ser_age2 = serialize($age);
?>
<?php print_r (unserialize($ser_first2)); ?>
<?php print_r (unserialize($ser_last2)); ?>
<?php print_r (unserialize($ser_age2)); ?>
[/code]
[code=php]
<?php
// POST data, be sure to sanitize them to prevent persistant xss and sql injection attacks
$first = $_POST["first"];
$last = $_POST["last"];
$age = $_POST["age"];
// Serialized and placed into db
$ser_first2 = serialize($first);
$ser_last2 = serialize($last);
$ser_age2 = serialize($age);
// Strings which should be requested from the db and then unserialized
$unser_first=unserialize($ser_first2)
$unser_last=unserialize($ser_last2)
$unser_age=unserialize($ser_age2)
// Use a loop of some sort to go through the array, you should choose
// one as the "key" array to base your count off of
$startloop=0;
while($startloop < count(unser_first)){
echo 'firstname: '.$unser_first[$startloop].', lastname: '.$unser_last[$startloop].', and their age: '.$unser_age[$startloop];
$startloop++;
}
[/code]
[code=php]
$first = $_POST["first"];
$last = $_POST["last"];
$age = $_POST["age"];
// Serialized and placed into db
$ser_first2 = serialize($first);
$ser_last2 = serialize($last);
$ser_age2 = serialize($age);
$item_purchased = serialize("$ser_first2"."$ser_last2"."$ser_age2");
[/code]
0.1.9 — BETA 5.18