PHP - Global Functions


 

$array = arrayDiffMultidim($array1, $array2)

Compare two multi-dimensional arrays and give the result of the differences between the two arrays.


							

 

$array = arrayReIndex($array)

Run through array and reindex, so the id are subsequent again.


			$stock = array(0 => "apple", 2 => "lemon", 1=> "peach");
$changes = arrayReIndex($stock);
var_dump($changes);

//== output
// array (size=3)
//   0 => string 'apple' (length=5)
//   1 => string 'lemon' (length=5)
//   2 => string 'peach' (length=5)		

 

$obj = compileObjectProps($array)

Compile an array of members with object properties into one object.


			$arr = array(
	(object) array("id"=>0,"Name"=>"abc"),
	(object) array("id"=>0,"Description"=>"lorem ispum")
);

var_dump(compileObjectProps($arr));

//== output
// object(stdClass)[30]
//   public 'id' => int 0
//   public 'Name' => string 'abc' (length=3)
//   public 'Description' => string 'lorem ispum' (length=11)		

 

$array = convertArrayMembers($array,$func)

Iterate through array or assorciative array and run the convert function for each member.


			$stock = array("oranges" => 8, "apples" => 4, "pears" => 3);

$changes = convertArrayMembers($stock,function ($value) {
	return ++$value;
});
var_dump($changes);

//== output
// array (size=3)
//   'oranges' => int 9
//   'apples' => int 5
//   'pears' => int 4		

 

$string = convertStringForJSString($string)

Covert a string to it can be handled by JavaScript properly.


			var_dump(convertStringForJSString("<br/>"));

//== output
// string '<br\/>' (length=6)		

 

exitJSError($string)

Exit the current run with a JavaScript error.


			exitJSError("unknown error");

//== output
//alert('unknown error');		

 

exitJSONError($string)

Exit the current run with a JSON error according to client.


			exitJSONError("unknown error");

//== output
//{"status":"error","errorText":"unknown error"}		

 

exitJSONNotice($string)

Exit the current run with a JSON notice according to client.


			exitJSONNotice("all okay");

//== output
//{"status":"notice","errorText":"all okay"}		

 

exitJSONWarning($string)

Exit the current run with a JSON warning according to client.


			exitJSONWarning("missing childs");

//== output
//{"status":"warning","errorText":"missing childs"}		

 

$array = findObjInArrOfObj($haystack,$needle)

Find needle-object in an array of objects and return the rowset.


			$Roles = array(
	(object) array("id"=>0,"Name"=>"abc"),
	(object) array("id"=>1,"Name"=>"cde")
);
$row = findObjInArrOfObj($Roles,(object) array("Name"=>"cde"));
var_dump($row);

//== output
// object(stdClass)[32]
//   public 'id' => int 1
//   public 'Name' => string 'cde' (length=3)		

 

$string = firstChar($string)

Return the first character of a String.


			var_dump(firstChar("abcd"));

//== output
// string 'a' (length=1)		

 

$obj = generateObjFromPropListArray($array)

Generate an empty object from an array of properties.


			$props = array("id","Name","Description");
var_dump(generateObjFromPropListArray($props));

//== output
//object(stdClass)[27]
//  public 'id' => null
//  public 'Name' => null
//  public 'Description' => null		

 

$string = generatePronouncableString($length)

Generate a pronouncable string of length $length.


			var_dump(generatePronouncableString(12));

//== output
// string 'wewepujiyudi' (length=12)		

 

$string = getETInPast()

Get the string of the last timestamp the ET connected.


			var_dump(getETInPast());

//== output
// string '2018-07-06 13:52:58' (length=19)		

 

$array = getIdArrFromRows($rows)

Get the id column of a data grid.


			$Roles = array(
	(object) array("id" => 1, "Name" => "admin", "Info" => null),
	(object) array("id" => 2, "Name" => "user", "Info" => null),
);

var_dump(getIdArrFromRows($Roles));

//== output
// array (size=2)
//   0 => int 1
//   1 => int 2		

 

$array = getKeysOfObject($object)

Get the keys of specified object.


			$Role = (object) array("id" => 1, "Name" => "admin", "Info" => null);

var_dump(getKeysOfObject($Role));

//== output
// array (size=3)
//   0 => string 'id' (length=2)
//   1 => string 'Name' (length=4)
//   2 => string 'Info' (length=4)		

 

$string = getModuleNameByFilePath($string)

Get the module name for a specified file path.


			var_dump(getModuleNameByFilePath("C:\Users\Username\workspace\ax\modules\DemoPlayG\dp\Playg.php"));

//== output
// string 'DemoPlayG' (length=9)		

 

$string = getModuleNameViaBacktrace()

Get the module name via backtrace.


			var_dump(getModuleNameViaBacktrace());

//== output
// string 'DemoPlayG' (length=9)		

 

$array = getPropArrFromRows($rows,$key)

Get the property column ($key) of a data grid.


			$Roles = array(
	(object) array("id" => 1, "Name" => "admin", "Info" => null),
	(object) array("id" => 2, "Name" => "user", "Info" => null),
);

var_dump(getPropArrFromRows($Roles,"Name"));

//== output
//array (size=2)
//  0 => string 'admin' (length=5)
//  1 => string 'user' (length=4)		

 

$string = getRandomHash()

Get a random hash (32 characters) for seeding or identification.


			var_dump(getRandomHash());

//== output
// string '4b086b408ac68dd59f598df69cf6d26f' (length=32)		

 

$boolean = hasRole($roleName)

Return whether the current session is valid for the specified role. A simple hasRole()-exitJSONError() is usually all you need to do to to safeguard all open ports of your module.


			if(hasRole("user")) {
	... // do the the privileged samba
}
else {
	exitJSONError("Missing rights");
}		

 

html_header()

Send the standard html header.

 

$boolean = isAssocArray($array)

Test whether the given array is an associative array.

 

$boolean = isValidDate($datestring)

Check whether the given string is in the format YYYY-MM-DD and a valid date.

 

$boolean = isValidDateTime($datestring)

Check whether the given string is in the format YYYY-MM-DD HH:MM:SS and a valid date-time.

 

$boolean = isValidEmail($string)

Check whether the given string is in the format of a valid email address.

 

$boolean = isValidTime($string)

Check whether the given string is in the format of a time signature HH:MM:SS.

 

json_die($variant)

Exit and dump the $variant data in JSON format.

 

json_dump($variant)

Dump the data of $variant in JSON format.


			$Roles = array(
	(object) array("id" => 1, "Name" => "admin", "Info" => null),
	(object) array("id" => 2, "Name" => "user", "Info" => null),
);
json_dump($Roles);

//== output
// [{"id":1,"Name":"admin","Info":null},{"id":2,"Name":"user","Info":null}]		

 

json_exit($variant)

Alias for json_die().

 

$string = lastChar($string)

Return the last character of a String.


			var_dump(lastChar("abcd"));

//== output
// string 'd' (length=1)		

 

$array = proofObj($proofObj,$dataObj)

Proof object $dataObj to the given criteria in $proofObj, if everthing is okay, return an empty error array.

The proof Object can hold the following values:
"boolean" | "integer" | "double" | "string" | "array" | "object" | "resource" | "NULL"

Precedent underscore (eg. "_string") means the property is optional.


			$proofObj = (object) array(
	"table" => "string",
	"data" => "array",
	"noLogFields" => "_array"
);

$dataObj = (object) array(
	"table" => "_sys_config"
);

var_dump(proofObj($proofObj, $dataObj));

//== output
//array (size=1)
//  0 => string 'the property (array) 'data' was not given' (length=41)		

 

$string = removeBlankLines($string)

Remove blank lines from a given (multiline) string.

 

$string = removeLastCharacter($string)

Remove last character from a given string.

 

$string = renderObjAsHTMLTable($string)

Remove last character from a given string.