Skip to content

Commit 22c8ad9

Browse files
committed
refactor: convert string & json encode decode helpers added
1 parent f0afd13 commit 22c8ad9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

includes/Core/Util/Helper.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,32 @@ public static function decodeHtmlEntities($input)
464464
return static::decodeSingleEntity($input);
465465
}
466466

467+
/**
468+
* Convert string to array.
469+
*
470+
* @param null|array|string $data
471+
* @param string $separator
472+
*
473+
* @return array
474+
*/
475+
public static function convertStringToArray($data, $separator = ',')
476+
{
477+
if (empty($data)) {
478+
return [];
479+
}
480+
481+
if (\is_array($data)) {
482+
return array_map('trim', $data);
483+
}
484+
485+
return array_map('trim', explode($separator, $data));
486+
}
487+
488+
public static function jsonEncodeDecode($data)
489+
{
490+
return json_decode(json_encode($data), true);
491+
}
492+
467493
private static function getVariableType($val)
468494
{
469495
$types = [

0 commit comments

Comments
 (0)