12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 6/7/16
- * Time: 5:04 PM
- */
-
- namespace Luticate\Utils\Business;
-
-
- class LuArrayUtils
- {
- public static function snakeToCamelCase($array)
- {
- if (!is_array($array))
- {
- return $array;
- }
- $camelCase = [];
- foreach ($array as $key => $value)
- {
- $camelCase[LuStringUtils::snakeToCamelCase($key, true)] = self::snakeToCamelCase($value);
- }
- return $camelCase;
- }
- public static function camelCaseToSnake($array)
- {
- if (!is_array($array))
- {
- return $array;
- }
- $camelCase = [];
- foreach ($array as $key => $value)
- {
- $camelCase[LuStringUtils::camelCaseToSnake($key, false)] = self::camelCaseToSnake($value);
- }
- return $camelCase;
- }
-
- public static function convertJsonString($json)
- {
- return LuStringUtils::convertJsonString($json);
- }
-
- public static function objectToArray($d)
- {
- if (is_object($d)) {
- $d = get_object_vars($d);
- }
-
- if (is_array($d)) {
- $data = [];
- foreach ($d as $key => $value) {
- $data[$key] = self::objectToArray($value);
- }
- return self::snakeToCamelCase($data);
- }
- else {
- return $d;
- }
- }
-
- }
|