table = $table; } public function fields($fields) { return $this; } public function execute() { } public function values($values) { global $tables; $tables[$this->table][] = $values; return $this; } } } namespace { list($progname, $dump) = $argv; include $dump; $links = $tables['menu_links']; // Replace plid, p* by paths. $by_mlid = array_combine(array_column($links, 'mlid'), $links); foreach ($links as $i => $link) { foreach ($link as $k => $v) { if ($k == 'plid' || preg_match('/^p\d/', $k)) { if (isset($by_mlid[$v])) { $links[$i][$k] = $by_mlid[$v]['link_path']; } } } } // Remove mlids. foreach ($links as $i => $link) { unset($links[$i]['mlid']); } // Sort by link_path, options. $paths = array_column($links, 'link_path'); $options = array_column($links, 'options'); array_multisort($paths, SORT_ASC, $options, SORT_ASC, $links); // Add nice keys for printing. $print = []; foreach ($links as $i => $link) { $path = $link['link_path']; if (isset($print[$path])) { $path .= ':' . $i; } $print[$path] = $link; } print_r($print); }