mirror of
https://github.com/friendica/friendica
synced 2025-04-30 09:04:22 +02:00
Moved function to Arrays.php
This commit is contained in:
parent
fbde999d0d
commit
a66bb09b40
3 changed files with 39 additions and 37 deletions
|
@ -29,7 +29,7 @@ class Arrays
|
|||
/**
|
||||
* Private constructor
|
||||
*/
|
||||
private function __construct () {
|
||||
private function __construct() {
|
||||
// Utitlities don't have instances
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class Arrays
|
|||
* @param string $glue Glue for imploded elements
|
||||
* @return string String with elements from array
|
||||
*/
|
||||
public static function recursiveImplode (array $array, $glue) {
|
||||
public static function recursiveImplode(array $array, $glue) {
|
||||
// Init returned string
|
||||
$string = '';
|
||||
|
||||
|
@ -62,4 +62,32 @@ class Arrays
|
|||
// Return it
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* walks recursively through an array with the possibility to change value and key
|
||||
*
|
||||
* @param array $array The array to walk through
|
||||
* @param callable $callback The callback function
|
||||
*
|
||||
* @return array the transformed array
|
||||
*/
|
||||
static public function walkRecursive(array &$array, callable $callback)
|
||||
{
|
||||
$new_array = [];
|
||||
|
||||
foreach ($array as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
if ($callback($v, $k)) {
|
||||
$new_array[$k] = self::walkRecursive($v, $callback);
|
||||
}
|
||||
} else {
|
||||
if ($callback($v, $k)) {
|
||||
$new_array[$k] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
$array = $new_array;
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue