2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Atli
0

Hey.

By "hash table" I assume you mean an associative array?
There isn't anything in PHP like the HashTable you find in .Net or Java. (There is no need for it, because of PHPs flexible array type.)

Anyhow, you can use the serialize and unserialize functions to create a data packet that you can store on your HDD, and restore it.

For example, to save an array to a file:

<?php
// Random example data
$fields = array(
  array('name' => 'Firstname', 'required' => true),
  array('name' => 'Lastname', 'required' => true),
  array('name' => 'Email', 'required' => true),
  array('name' => 'EmailCheck', 'required' => true),
  array('name' => 'Password', 'required' => true),
  array('name' => 'PasswordCheck', 'required' => true)
);

// Serialize it into a storable data packet.
$data = serialize($fields);

// Write the data to a file
$filename = "/path/to/my/file.txt";
file_put_contents($filename, $data);
?>

And to restore it:

<?php
// Fetch the data from a file
$filename = "/path/to/my/file.txt";
$data = file_get_contents($filename);

// Restore the data into it's original form
$fields = unserialize($data);

// Print them, or whatever.
var_dump($fields);
?>

Edited by Atli: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.