Skip to content

Instantly share code, notes, and snippets.

View varrg's full-sized avatar

Dan Boklöv Palovaara varrg

  • Sweden
View GitHub Profile
<?php
/**
* Return a limited array balanced on the current page
*
* @param int $current page
* @param int $total pages
* @param int $max pages listed, a value of -1 shows all
* @param bool $include_edges always include first and last pages
*
<?php
/**
* Create an array by using one array for keys and another for its values
*
* Mimics the behaviour of {@link https://www.php.net/manual/function.array-combine.php array_combine()}
* with the exception that duplicate string keys are merged into an array instead of overwritten.
*/
function array_combine_duplicate(array $keys, array $values): array {
if (count($keys) != count($values)) {
<?php
/**
* Merge one or more arrays recursively
*
* Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one.
*
* If the input arrays have the same string keys, then the latter value for that key will overwrite the previous one,
* and this is done recursively, so that if one of the values is an array itself, the function will merge it with a corresponding entry in another array too.
* If, however, the arrays have the same numeric key, the latter value will not overwrite the original value, but will be appended.