gapi_tools.inc
Basic tools
License
MIT-style license.
Version
v0.3
GAPI Copyright
copyright © 2007 Gregory Koberger http://www.gkoberger.net
ToDo
- Add JSON support to toArray
- Add toArray support to everything
Summary
Basic tools | |
A class that contains basic tools | |
Turns keys with no value into a key rather than a value | |
Converts strings and JSON (PHP 5.2.0+ only) into arrays. | |
Returns the first element of an array | |
Returns the last element of an array |
convertArray
function convertArray( $array )
Turns keys with no value into a key rather than a value
Parameters
| $array | The array to be converted |
Examples
$array = array( value1 => 'Value 1', value2 , value3 => 3);
print_r( $array );
// Returns:
// Array
// (
// [value1] => Value 1
// [0] => value2
// [value3] => 3
// )
$arrayNew = $gapi_tools->convertArray( $array );
// Returns:
// Array
// (
// [value1] => Value 1
// [value2] => true
// [value3] => 3
// )
Returns
A converted array
toArray
function toArray( $input )
Converts strings and JSON (PHP 5.2.0+ only) into arrays.
Note: Arrays are accepted, and are returned untouched. This function is used for if you want to accept both strings and arrays.
Parameters
| $input | The input or string to be converted |
Examples
$arrayNew = gapiTools::toArray( "Test String" );
// Returns:
// Array
// (
// [0] => 'Test String'
// )
Returns
An array
getFirst
function getFirst( $array )
Returns the first element of an array
Functions much like array_shift, without modifying the original array
Parameters
| $array | The array to be converted |
Examples
$first = gapiTools::getFirst( array( 'a'=>'apple', 'b'=> 'boy' );
// Returns:
// apple
Returns
The first element of the array (as a string)
Turns keys with no value into a key rather than a value
function convertArray( $array )
Converts strings and JSON (PHP 5.2.0+ only) into arrays.
function toArray( $input )
Returns the first element of an array
function getFirst( $array )
Returns the last element of an array
function getLast( $array )