PHPCoreStdfuncs - A useful Library for common programming tasks
The File stdfuncs.inc.php contains a bunch of commonly used functions. I designed it firstly to my own needs as PHP-Developer.
The functions are grouped in some classes just to keep a bit of order and structure in it. The most important classes are:
debug contains functions to debug variable content and Time measurment
arrayfunc contains some functions to handle arrays especially 2-D arrays (tables)
trans contains functions to transform something, e.g. a PHP array into its JSON representation
creates something like this (probably more usable than the output of print_r..)
[title]
string
myString
empty
""
number
90
null
null
sub_array
stringmyStringempty""number90nullnull
sub_array_2
0myString1""2903null
sub_array_3
empty-array
The Second Argument is useful if you debug more than one variable, to seperate them from each other.
The command debug::get() works equally but returns the html-code instead of direcly printing it to the standard-output, in fact debug::show(...) is a shortcut from print(debug::get(...))
$sorted= arrayfunc::tableSort($tableData,"name");
debug::show($sorted,"sorted by name");
sorted by name
0
namehollenbeckfirstnamejohn
1
namekernfirstnamemike
2
namekernfirstnamebill
3
nameschultzfirstnameroland
Sorting by firstname descending, unsing the holdIndizes option
The 3. argument "DESC" indicates to sort reverse, the 4. argument is called holdIndizes, if set the key => record relation will stay the same
(useful if the indizes are e.g. databese ids).
$sorted= arrayfunc::tableSort($tableData,"firstname","DESC",true);
debug::show($sorted,"sorted by firstname");
var tableData = [{"name":"kern","firstname":"mike"},{"name":"hollenbeck","firstname":"john"},{"name":"schultz","firstname":"roland"},{"name":"kern","firstname":"bill"}];