From: henoheno Date: Sat, 16 Jun 2007 05:02:46 +0000 (+0900) Subject: * TODO: ltrim('.') from $trie X-Git-Url: http://git.osdn.net/view?p=pukiwiki%2Fpukiwiki_sandbox.git;a=commitdiff_plain;h=b4894f2013b4131d59012ff754aa70f84b5424c3 * TODO: ltrim('.') from $trie * TODO: from array('foobar' => 'foobar') to 'foobar' --- diff --git a/spam/spam.php b/spam/spam.php index aca2528..2f600a2 100644 --- a/spam/spam.php +++ b/spam/spam.php @@ -1,5 +1,5 @@ 'foobar') to 'foobar' + // Format: From array('foobar' => 'foobar') to 'foobar' + $tmp = array(); + foreach($trie as $key => $value) { + $tmp[] = ' \'' . + (($trie[$key] == $key) ? $key : $key . '\' => \'' . $trie[$key]) + . '\','; + unset($trie[$key]); + } - return var_export_shrink($trie, TRUE, TRUE); + return 'array (' . "\n" . implode("\n", $tmp) . "\n" . ')'; } // ksort() by domain @@ -1581,7 +1586,7 @@ function ksort_by_domain(& $array) // array('F' => array('B' => array('C' => array('d' => array('' => 'foobar'))))) // to // array('F.B.C.d.' => 'foobar') -function array_joinbranch_leaf(& $array, $delim = '.', $limit = 0, $reverse = FALSE) +function array_joinbranch_leaf(& $array, $delim = '.', $limit = 0, $reverse = FALSE, $stopword = NULL) { $result = array(); if (! is_array($array)) return $result; // Nothing to do @@ -1597,6 +1602,7 @@ function array_joinbranch_leaf(& $array, $delim = '.', $limit = 0, $reverse = FA $cursor = & $single; while(is_array($cursor) && count($cursor) == 1) { // Once ++$k; + if (key($cursor) === $stopword) break; $kstack[] = key($cursor); $cursor = & $cursor[$kstack[$k]]; if ($limit != 0 && $k == $limit) break;