$maVal) { $found = false; foreach($array as $aKey => $aVal) { if ((string)$maKey == (string)$aKey){ $found = true; if (is_array($maVal) && is_array($aVal)){ $array[$maKey] = static::merge($aVal, $maVal); } else { if (is_array($aVal)){ $array[$maKey] = static::merge($aVal, array($maVal)); } elseif (is_array($maVal)){ $array[$maKey] = static::merge(array($aVal), $maVal); } else { //merge logic if (!is_numeric($maKey)){ $array[$maKey] = $maVal; } elseif (!in_array($maVal, $array)) { $array[] = $maVal; } //END: merge ligic } } break; } } // add an item if key not found if (!$found){ $array[$maKey] = $maVal; } } return $array; } /** * Get a full path of the file * * @param string $folderPath - Folder path, Ex. myfolder * @param string $filePath - File path, Ex. file.json * * @return string */ public static function concatPath($folderPath, $filePath='') { if (empty($filePath)) { return $folderPath; } if (empty($folderPath)) { return $filePath; } else { if (substr($folderPath, -1) == static::getSeparator()) { return $folderPath . $filePath; } return $folderPath . static::getSeparator() . $filePath; } } /** * Convert array to object format recursively * * @param array $array * @return object */ public static function arrayToObject($array) { if (is_array($array)) { return (object) array_map("static::arrayToObject", $array); } else { return $array; // Return an object } } /** * Convert object to array format recursively * * @param object $object * @return array */ public static function objectToArray($object) { if (is_object($object)) { $object = (array) $object; } return is_array($object) ? array_map("static::objectToArray", $object) : $object; } /** * Appends 'Obj' if name is reserved PHP word. * * @param string $name * @return string */ public static function normilizeClassName($name) { if (in_array($name, self::$reservedWords)) { $name .= 'Obj'; } return $name; } /** * Get Naming according to prefix or postfix type * * @param string $name * @param string $prePostFix * @param string $type * * @return string */ public static function getNaming($name, $prePostFix, $type = 'prefix', $symbol = '-') { if ($type == 'prefix') { return static::toCamelCase($prePostFix.$symbol.$name, false, $symbol); } else if ($type == 'postfix') { return static::toCamelCase($name.$symbol.$prePostFix, false, $symbol); } return null; } /** * Replace $search in array recursively * * @param string $search * @param string $replace * @param string $array * @param string $isKeys * * @return array */ public static function replaceInArray($search = '', $replace = '', $array = false, $isKeys = true) { if (!is_array($array)) { return str_replace($search, $replace, $array); } $newArr = array(); foreach ($array as $key => $value) { $addKey = $key; if ($isKeys) { //Replace keys $addKey = str_replace($search, $replace, $key); } // Recurse $newArr[$addKey] = static::replaceInArray($search, $replace, $value, $isKeys); } return $newArr; } } ?>