PHP

Created Sunday 23 March 2014

Sorting multidimensional array:
http://stackoverflow.com/questions/2699086/sort-multi-dimensional-array-by-value
private function aasort (&$array, $key) {
$sorter=array();
$ret=array();
reset($array);
foreach ($array as $ii => $va) {
$sorter[$ii]=$va[$key];
}
asort($sorter);
foreach ($sorter as $ii => $va) {
$ret[$ii]=$array[$ii];
}
$array=$ret;
}

Creating CSV:
(Fix - fputcsv() expects array as the 2nd parameter)
http://stackoverflow.com/questions/16391528/query-mysql-and-export-data-as-csv-in-php

Get request body:
http://stackoverflow.com/questions/8945879/how-to-get-body-of-a-post-in-php
**$entityBody = file_get_contents('php://input');**
OR
$entityBody = stream_get_contents(STDIN);

Comparing Timestamps
http://stackoverflow.com/questions/14647338/comparing-timestamp-to-current-time-from-database
$time = strtotime($timest);

$curtime = time();

if(($curtime-$time) > 1800) {
//do stuff
}

Class autoloader example
http://php.net/manual/en/function.spl-autoload-register.php
spl_autoload_register(function ($class) {
include 'classes/' . $class . '.php';
});



Backlinks: