[TASK] Move array functions to utility class

This commit is contained in:
Philipp Dieter
2021-03-16 17:00:09 +01:00
parent 329fa6d313
commit 221eda9f44
2 changed files with 52 additions and 31 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace Cjel\TemplatesAide\Utility;
/***
*
* This file is part of the "" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2021 Philipp Dieter
*
***/
/**
*
*/
class ArrayUtility
{
/**
* function arrayTobject
*/
public static function toObject($array) {
if (is_array($array)) {
return (object) array_map([__CLASS__, __METHOD__], $array);
} else {
return $array;
}
}
/**
* remove empty strings
*/
public static function removeEmptyStrings($array)
{
foreach ($array as $key => &$value) {
if (is_array($value)) {
$value = [__CLASS__, __METHOD__]($value);
} else {
if (is_string($value) && !strlen($value)) {
unset($array[$key]);
}
}
}
unset($value);
return $array;
}
}