The following is a neat use for extract to store and manipulate large amounts of form data from. I basically loop through the $_POST and implode it seperating the key and value pairs by a space. Then store it in a db, the reversing function basically explodes the string to a array. Then converts the indexed array to a associative array then uses extract to seal the deal and make it easily available within a program. My main reason for sharing these are the fact I make some big web applications that store allot of forum data in a DB and these functions make it very easy to quickly and easily store and recall the data. I've contributed it because I spent many hours creating this code and recall going "I wish someone had previously submitted it to the page notes". Would have saved me allot of time and agony and I'm sure I'm not the only person that could really benefit from it, so I decided to share.



<?php

$stack = array();

foreach ( $_POST as $key => $value ) {

array_push ( $stack , $key , $value );

}

$block = implode ( " " , $stack ); $query = "INSERT INTO `sometable` VALUES('" . $seluser . "','" . addslashes ( $block ). "');" ;

$result = mysql_query ( $query ) or die( "Query failed for block insert: " . mysql_error ());

?>



The nice thing is with the above we can quickly create a string of key and value pairs from the data the script got. Without really caring what their names are. You know how if register globals are on you say $someformvar rather than $_POST["someformvar"]; , basically the code below reads this previous created block returns it to that state. Sort of like presistant register globals.



<?php

$query = "SELECT * FROM `sometable` WHERE `blockid` = '" . addslashes ( $bid ). "';" ;

$result = mysql_query ( $query ) or die( "Query failed read: " . mysql_error ());

$sql = mysql_fetch_array ( $result , MYSQL_ASSOC );

$array = eplode ( " " , $sql [ "data" ]);

for ( $i = 0 ; $i < sizeof ( $array ); $i += 2 ) {

$myassoc [ $array [ $i ]] = isset( $array [ $i + 1 ])? $array [ $i + 1 ]: NULL ;

}

extract ( $myassoc , EXTR_OVERWRITE );

?>