]> git.mxchange.org Git - friendica.git/blob - src/Util/Arrays.php
Merge pull request #6127 from annando/notice
[friendica.git] / src / Util / Arrays.php
1 <?php
2 /**
3  * @file src/Util/Arrays.php
4  * @author Roland Haeder<https://f.haeder.net/profile/roland>
5  */
6 namespace Friendica\Util;
7
8 /**
9  * @brief Array utility class
10  */
11 class Arrays
12 {
13         /**
14          * @brief Private constructor
15          */
16         private function __construct () {
17                 // Utitlities don't have instances
18         }
19
20         /**
21          * @briefs Implodes recursively a multi-dimensional array where a normal implode() will fail.
22          *
23          * @param array  $array Array to implode
24          * @param string $glue  Glue for imploded elements
25          * @return string String with elements from array
26          */
27         public static function recursiveImplode (array $array, $glue) {
28                 // Init returned string
29                 $string = '';
30
31                 // Loop through all records
32                 foreach ($array as $element) {
33                         // Is an array found?
34                         if (is_array($element)) {
35                                 // Invoke cursively
36                                 $string .= '{' . self::recursiveImplode($element, $glue) . '}' . $glue;
37                         } else {
38                                 // Append normally
39                                 $string .= $element . $glue;
40                         }
41                 }
42
43                 // Remove last glue
44                 $string = trim($string, $glue);
45
46                 // Return it
47                 return $string;
48         }
49 }