Skip to content

Instantly share code, notes, and snippets.

@rahuldottech
Last active August 26, 2018 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahuldottech/3ad60944374c6aaf657588787dd0bdcd to your computer and use it in GitHub Desktop.
Save rahuldottech/3ad60944374c6aaf657588787dd0bdcd to your computer and use it in GitHub Desktop.
Usage examples for varDx
<?php
require 'varDx.php';
$dx = new \varDx\cDX; //create object
$dx->def('file1.txt'); //define data file
$a = "this is a string";
$dx->write('val1', $a); //write key to file
$dx->modify('val1', "this is another string"); //modify value of key
echo $dx->read('val1'); //read value of key
if($dx->check('val1')){ //check if key exists
del('val1'); //delete key
}
<?php
/*
Say you have multiple users, and you want to store details of all of them in the same file.
In that case, you can do something like this:
*/
require 'varDx.php';
$dx = new \varDx\cDX; //create object
$dx->def('file1.txt'); //define data file
$user1 = "tom";
$user2 = "tim";
$dx->write($user1.'_address', "somevalue"); //write key to file
$dx->write($user2.'_address', "somevalue"); //write key to file
/*
Here the effective key names are "tom_address" and "tim_address".
*/
<?php
/*
You can create multiple objects to deal with multiple files too!
*/
require 'varDx.php';
$dx1 = new \varDx\cDX; //create object
$dx2 = new \varDx\cDX; //create another object
$dx1->def('file1.txt'); //define data file
$dx2->def('file2.txt'); //define data file
$dx1->write('val1', "somevalue"); //write key to file1.txt
$dx2->write('val1', "somevalue"); //write key to file2/txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment