3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Util;
32 private function __construct() {
33 // Utilities don't have instances
37 * Implodes recursively a multi-dimensional array where a normal implode() will fail.
39 * @param array $array Array to implode
40 * @param string $glue Glue for imploded elements
41 * @return string String with elements from array
43 public static function recursiveImplode(array $array, $glue) {
44 // Init returned string
47 // Loop through all records
48 foreach ($array as $element) {
50 if (is_array($element)) {
52 $string .= '{' . self::recursiveImplode($element, $glue) . '}' . $glue;
55 $string .= $element . $glue;
60 $string = trim($string, $glue);
67 * walks recursively through an array with the possibility to change value and key
69 * @param array $array The array to walk through
70 * @param callable $callback The callback function
72 * @return array the transformed array
74 public static function walkRecursive(array &$array, callable $callback)
78 foreach ($array as $k => $v) {
80 if ($callback($v, $k)) {
81 $new_array[$k] = self::walkRecursive($v, $callback);
84 if ($callback($v, $k)) {