3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Arr { public static function dot($array, $prepend = '') { $output = array(); foreach($array as $k => $v) { if(is_array($v)) { $output = array_merge($output, static::dot($v, $prepend . $k . '.')); } else { $output[$prepend . $k] = $v; } } return $output; } public static function dotRev($array, $count = 1, $keySearchPrepend = '') { $output = array(); foreach($array as $ks => $v) { $ks2 = explode('.', $ks); $k = static::lastV($ks2); if(count($ks2) > $count) { $output[$k] = static::dotRev($array, $count + 1, $keySearchPrepend . $k . '.'); } else { if($ks !== $keySearchPrepend . $k) continue; $output[$k] = $v; } } } public static function firstV($array) { if(count($array) < 1) return null; $values = array_values($array); return $values[0]; } public static function lastV($array) { if(count($array) < 1) return null; $values = array_values($array); return $values[(count($values) - 1)]; } public static function firstK($array) { if(count($array) < 1) return null; $values = array_keys($array); return $values[0]; } public static function lastK($array) { if(count($array) < 1) return null; $values = array_keys($array); return $values[(count($values) - 1)]; } } var_export(Arr::dotRev(array ( 'app.config.enviornments.development.0' => 'development.meta.php', 'app.config.enviornments.maintanence.0' => 'maintanence.meta.php', 'app.config.enviornments.production.0' => 'production.meta.php', 'app.config.subdomains.blog.0' => 'blog.meta.php', 'app.config.subdomains.files.0' => 'files.meta.php', 'app.config.subdomains.i.0' => 'i.meta.php', 'app.config.subdomains.www.0' => 'paths.php', 'app.config.subdomains.www.1' => 'www.meta.php', 'app.config.0' => 'app.php', 'app.config.1' => 'database.php', 'app.config.2' => 'paths.php', 'app.0' => 'routing.php', 'bootstrap.0' => 'autoload.php', 'engine.Assets.0' => 'Asset.php', 'engine.Assets.1' => 'Assets.php', 'engine.Console.0' => 'Factory.php', 'engine.Console.1' => 'Manager.php', 'engine.Core.App.0' => 'Application.php', 'engine.Core.App.1' => 'Enviornments.php', 'engine.Core.Errors.0' => 'Error.php', 'engine.Core.Errors.1' => 'ErrorMessages.php', 'engine.Core.Errors.2' => 'Errors.php', 'engine.Core.Settings.0' => 'Factory.php', 'engine.Core.Settings.1' => 'Settings.php', 'engine.Core.0' => 'Constants.php', 'engine.Core.1' => 'Functions.php', 'engine.Database.QueryBuilder.0' => 'Builder.php', 'engine.Database.QueryBuilder.1' => 'Factory.php', 'engine.Database.0' => 'Database.php', 'engine.Filesystem.Exception.0' => 'FileNotFound.php', 'engine.Filesystem.Exception.1' => 'Filesytem.php', 'engine.Filesystem.0' => 'Directory.php', 'engine.Filesystem.1' => 'File.php', 'engine.Filesystem.2' => 'FilePartInterface.php', 'engine.Filesystem.3' => 'Filesystem.php', 'engine.Html.Table.0' => 'AbstractTablePart.php', 'engine.Html.Table.1' => 'TableBody.php', 'engine.Html.Table.2' => 'TableBuilder.php', 'engine.Html.Table.3' => 'TableFooter.php', 'engine.Html.Table.4' => 'TableHeader.php', 'engine.Html.Table.5' => 'TableRow.php', 'engine.Html.0' => 'Assets.php', 'engine.Html.1' => 'HtmlFactory.php', 'engine.Html.2' => 'HtmlTag.php', 'engine.Html.3' => 'HtmlTags.php', 'engine.Http.Request.0' => 'Factory.php', 'engine.Http.Request.1' => 'HttpRequest.php', 'engine.Http.Request.2' => 'HttpResponse.php', 'engine.Http.Route.0' => 'Router.php', 'engine.Logger.Loggers.0' => 'ConsoleLogger.php', 'engine.Logger.Loggers.1' => 'DevWebLogger.php', 'engine.Logger.Loggers.2' => 'NullLogger.php', 'engine.Logger.Loggers.3' => 'StandardLogger.php', 'engine.Logger.Loggers.4' => 'WebLogger.php', 'engine.Logger.0' => 'AbstractLogger.php', 'engine.Logger.1' => 'LoggerInterface.php', 'engine.Logger.2' => 'LoggerLevel.php', 'engine.Request.0' => 'Factory.php', 'engine.Request.1' => 'Request.php', 'engine.Support.DataTypes.0' => 'Arr.php', 'engine.Support.Interfaces.0' => 'Arrayable.php', 'engine.Support.Interfaces.1' => 'Renderable.php', 'engine.Support.0' => 'ArrayUtils.php', 'engine.Support.1' => 'Constants.php', 'engine.Support.2' => 'DataUtils.php', 'engine.Support.3' => 'Factory.php', 'engine.Support.4' => 'StaticInstance.php', 'engine.Support.5' => 'StringUtils.php', 'engine.Support.6' => 'Utilities.php', 'engine.Views.0' => 'AbstractTemplate.php', 'engine.Views.1' => 'CompiledTemplate.php', 'engine.Views.2' => 'NativeTemplate.php', 'engine.Views.3' => 'TemplatingErrorExcpetion.php', 'engine.Views.4' => 'ViewNotFoundException.php', 'engine.Widgets.FileStructure.0' => 'Factory.php', 'engine.Widgets.FileStructure.1' => 'FileStructure.php', 'public.www.0' => 'index.php', 0 => '.htaccess', 1 => 'debug.txt', 2 => 'debug2.txt', 3 => 'debug3.txt', 4 => 'output.txt', 5 => 'test.php', )));

preferences:
38.5 ms | 402 KiB | 5 Q