function test_compact_list() { $levels = array(1, 3, 1, 1, 3, 2, 3); $parse = sonots::compact_list($levels); $truth = array(1, 2, 1, 1, 2, 2, 3); $this->assertEqual($parse, $truth); $levels = array(1, 3, 1, 1, 3, 3, 3); $parse = sonots::compact_list($levels); $truth = array(1, 2, 1, 1, 2, 2, 2); $this->assertEqual($parse, $truth); }
/** * Compact depth of headlines * * @access public * @access static * @param array &$headlines */ function compact_depth(&$headlines) { $pages = sonots::get_members($headlines, 'page'); // perform compact separately for each page foreach (array_unique($pages) as $page) { $keys = sonots::grep_array($page, $pages, 'eq'); $page_headlines = array_intersect_key($headlines, $keys); $depths = sonots::get_members($page_headlines, 'depth'); $depths = sonots::compact_list($depths); foreach ($depths as $key => $depth) { $headlines[$key]->depth = $depth; } } }