2018-07-31 01:24:26 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file src/Util/Arrays.php
|
|
|
|
* @author Roland Haeder<https://f.haeder.net/profile/roland>
|
|
|
|
*/
|
|
|
|
namespace Friendica\Util;
|
|
|
|
|
|
|
|
/**
|
2020-01-19 06:05:23 +00:00
|
|
|
* Array utility class
|
2018-07-31 01:24:26 +00:00
|
|
|
*/
|
|
|
|
class Arrays
|
|
|
|
{
|
|
|
|
/**
|
2020-01-19 06:05:23 +00:00
|
|
|
* Private constructor
|
2018-07-31 01:24:26 +00:00
|
|
|
*/
|
|
|
|
private function __construct () {
|
|
|
|
// Utitlities don't have instances
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-01-19 20:44:01 +00:00
|
|
|
* Implodes recursively a multi-dimensional array where a normal implode() will fail.
|
2018-07-31 01:24:26 +00:00
|
|
|
*
|
|
|
|
* @param array $array Array to implode
|
|
|
|
* @param string $glue Glue for imploded elements
|
|
|
|
* @return string String with elements from array
|
|
|
|
*/
|
|
|
|
public static function recursiveImplode (array $array, $glue) {
|
|
|
|
// Init returned string
|
|
|
|
$string = '';
|
|
|
|
|
|
|
|
// Loop through all records
|
|
|
|
foreach ($array as $element) {
|
|
|
|
// Is an array found?
|
|
|
|
if (is_array($element)) {
|
|
|
|
// Invoke cursively
|
|
|
|
$string .= '{' . self::recursiveImplode($element, $glue) . '}' . $glue;
|
|
|
|
} else {
|
|
|
|
// Append normally
|
|
|
|
$string .= $element . $glue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove last glue
|
|
|
|
$string = trim($string, $glue);
|
|
|
|
|
|
|
|
// Return it
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
}
|