4. Advanced features - adwins/Arrayer GitHub Wiki
4. Advanced features.
Advanced features.
/**
* Get an independent copy of current object.
*/
$copy = $arrayer->copy();
/**
* Get a copy with initial values, not trimmed at construct, not modified by methods, etc.
*/
$initial = $arrayer->initial();
/**
* Get a copy with initial trimmed values, not modified by methods, etc.
*/
$initial = $arrayer->initial(true);
/**
* Reset initial values to current values.
* After this method Arrayer:initial() will return existed values by moment when Arrayer::reset() have been called.
*/
$arrayer->reset();
/**
* Provide additional values to the object collection.
*/
$arrayer->values($values [, $expected=null [, $trim=false ] ]);
/**
* Undo any changes to initial values.
*/
$arrayer->username->undo();
/**
* You can combine methods.
*/
$arrayer->username->clean()->reset()->to_lower()->undo();
/**
* This example cleans username, resets initial, transforms to lower and undoes to clean value again.
*/
/**
* You can iterate Arrayer object
*/
foreach ($arrayer as $variable => $value){
$value->to_lower();
}
/**
* Getting data as array
*/
$simple_array = $arrayer->as_array();
/**
* Getting data as json
*/
$json_string = $arrayer->as_json();
/**
* Sending data as POST request
*/
$response = $arrayer->post('http://example.com/');
/**
* Exporting data to $_POST variable
*/
$arrayer->export();
/**
* Getting data as query
*/
$url = 'http://example.com/?' . $arrayer->as_query();
/**
* This results to: http://example.com/?username=John%20Smith&age=30
*/
$url = 'http://example.com/?' . $arrayer->as_query('&');
/**
* This results to: http://example.com/?username=John%20Smith&age=30
*/
/**
* Getting data as safe SQL query
*/
$sql = 'UPDATE `users` SET '
. $arrayer->as_sql_query()
. ' WHERE `id` = "'
. $arrayer->id->as_sql_query()
. '" LIMIT 1';
/**
* This results to:
* UPDATE `users` SET `username`="John Smith", `age`="30", `email`="[email protected]",
* `id`="13" WHERE `id`="13" LIMIT 1
*/
$sql = 'UPDATE `users` SET '
. $arrayer->as_sql_query(array('username', 'age'))
. ' WHERE `id` = "'
. $arrayer->id->as_sql_query()
. '" LIMIT 1';
/**
* This results to:
* UPDATE `users` SET `username`="John Smith", `age`="30" WHERE `id`="13" LIMIT 1
*/
$sql = 'INSERT INTO `users` '
. $arrayer->as_sql_query(null, true);
/**
* This results to:
* INSERT INTO `users` (`username`, `age`, `email`)
* VALUES ("John Smith", "30", "[email protected]")
*/