21 November, 2008, 02:47:15 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: We Return!
 

Pages: [1]   Go Down
  Print  
Author Topic: Updating Serialized Arrays.  (Read 1228 times)
0 Members and 1 Guest are viewing this topic.
http://Nevux.net

Demonic Pwns

Ex-Staff

Platinum Contribution
*
Hero Member

Karma: 3
Offline Offline

Gender: Male
Posts: 549
281704.25 Secksi Coins

View Inventory
Send Money to Slaytanist2

View Profile WWW
« on: 23 March, 2007, 08:20:07 AM »

Updating a serialized array.

First off we all should know how to use serialize().

Serialize is a function that takes arrays into strings for easier storing.

So in this tutorial you will learn how to update a serialize array.

First off lets create our array:

Code:
<?php

$array 
= array(=> "one");

?>


To serialize arrays all you do is put the array between the parameters for the serialize function like so:

Code:
<?php

$array 
= array(=> "one");
$a serialize($array);
?>


This will output the following:

Code:
a:1:{i:1;s:3:"one";}

Now lets unserialize the $a variable and update the array.

Code:
<?php

$array 
= array(=> "one");
$a serialize($array);

$arrah unserialize($a);
?>


This above would output the array back into array form using $arrah to access its values.

Code:
<?php

$array 
= array(=> "one");
$a serialize($array);

$arrah unserialize($a);

$arrah[1] = "uno";
$arrah[2] = "two";
$thearray serialize($arrah);
?>


Alright how serialize works is when you unserialize arrays there already in array form so everytime you add a array like so:

array
  • (x  being the key).

It will either add another key/value or update a key/value of an already existing array.

Now thats the basics on how to update a serialized array in PHP.

Have fun its useful.

Example:

http://www.nbboard.zoomcities.com/serialize.php

If can't view link heres result:

Code:

<?php
$array 
serialize(array(=> "one"));
echo 
$array;
$array2 unserialize($array);

$array2[1] = "uno";
$array2[2] = "two";
$arrah serialize($array2);

echo 
"<br />".$arrah;

?>





a:1:{i:1;s:3:"one";}
a:2:{i:1;s:3:"uno";i:2;s:3:"two";}
Logged


This resource was found useful by 0 out of 0 members. Rate it: [applaud] [smite]
Pages: [1]   Go Up
  Print  
 
Jump to:  
Sponsored Links:

Powered by MySQL
Powered by PHP
Powered by SMF 1.1.1 | SMF © 2005, Simple Machines LLC
TinyPortal v0.8.6 © Bloc
The rest copyright TCZ you pillocking twat!
Valid XHTML 1.0!
Valid CSS!
Places we'd like you to visit.