本文整理汇总了PHP中recurse函数的典型用法代码示例。如果您正苦于以下问题:PHP recurse函数的具体用法?PHP recurse怎么用?PHP recurse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了recurse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: recurse
function recurse($qtyOrdered, &$packsToOrder = array())
{
$widgetPacks = array(250, 500, 1000, 2000, 5000);
$widgetPacksReversed = array_reverse($widgetPacks);
foreach ($widgetPacksReversed as $key => $widgetPackQty) {
// if exact match
if ($qtyOrdered == $widgetPackQty) {
$packsToOrder[] = '1 x' . $widgetPackQty;
return $packsToOrder;
}
$nextKey = $key + 1;
$nextNextKey = $key + 2;
$previousKey = $key - 1;
//if between two pack numbers (500 and 1000. Current is 1000)
if ($qtyOrdered < $widgetPackQty && $qtyOrdered > $widgetPacksReversed[$nextKey]) {
$newQty = $qtyOrdered - $widgetPacksReversed[$nextKey];
if ($newQty < $widgetPacksReversed[$nextNextKey]) {
$packsToOrder[] = '1 x ' . $widgetPacksReversed[$nextKey];
recurse($newQty, $packsToOrder);
} else {
$packsToOrder[] = '1 x ' . $widgetPackQty;
}
}
}
return $packsToOrder;
}
示例2: recurse
/**
* Recursively processes a path and extracts JSDoc comment data from
* every .js file it finds.
* @param $path
*/
function recurse($path)
{
$fList = scandir($path);
foreach ($fList as $key => $val) {
switch ($val) {
case '.':
case '..':
// Ignore these entries
break;
default:
if (is_dir($path . '/' . $val)) {
// The entry is a folder so recurse it
recurse($path . '/' . $val);
} else {
// The entry is a file, check if it's a .js file
if (substr($val, strlen($val) - 3, 3) === '.js') {
// Process the JS file
echo 'Processing JavaScript file: ' . $path . '/' . $val . '<BR>';
$data = parseFile($path . '/' . $val);
processData($data, $path . '/' . $val, $val);
}
}
break;
}
}
}
示例3: updateLanguage
function updateLanguage($lang)
{
global $messages, $languagePack;
echo $lang, "... ";
ob_start();
$messages = array();
$languagePack = array();
$langFile = "../lib/lang/" . $lang . "_lang.php";
if (file_exists($langFile)) {
include $langFile;
}
echo "<?php\n\$languagePack = array(\n";
recurse('find_strings');
$textWritten = false;
foreach ($languagePack as $original => $translated) {
if (!isset($messages[$original])) {
if (!$textWritten) {
echo "\n// Strings no longer used\n";
}
$textWritten = true;
$translated = trim($translated);
if ($translated) {
echo var_export($original, true), " =>\n", var_export($translated, true), ",\n\n";
}
}
}
echo ");\n";
$stuff = ob_get_contents();
ob_end_clean();
file_put_contents($langFile, $stuff);
echo "Ok.\n";
}
示例4: recurse
function recurse(sfFilebasePluginFile $source, sfFilebaseDirectory $parent_dir, $file_mode)
{
try {
foreach ($source as $file) {
if ($file instanceof sfFilebasePluginDirectory) {
fwrite(STDOUT, sprintf("\n Creating directory %s in %s\n", $source->getFilename(), $parent_dir->getFilename()));
$node = new sfFilebaseDirectory();
$hash = md5(uniqid(rand(), true));
$node->setHash($hash);
$node->setFilename($file->getFilename());
$node->save();
$node->getNode()->insertAsLastChildOf($parent_dir);
recurse($file, $node, $file_mode);
} else {
fwrite(STDOUT, sprintf("\n Copying %s to %s\n", $source->getPathname(), $parent_dir->getFilename()));
$copy = $file->copy($source->getFilebase()->getPathname(), true);
$hash = $hash = md5(uniqid(rand(), true)) . '.' . $copy->getExtension();
$node = new sfFilebaseFile();
$node->setFilename($copy->getFilename());
$node->setHash($hash);
$node->save();
$node->getNode()->insertAsLastChildOf($parent_dir);
$move = $copy->move($hash);
$move->chmod($file_mode);
}
}
} catch (Exception $e) {
throw new Exception((string) $e);
}
}
示例5: recurse
/**
* Recursively creates tree with children
* @param $tree - current level tree node
*/
function recurse(&$tree)
{
global $words;
// for each child
for ($i = 0; $i < count($tree->children); $i++) {
$c = '';
$pos = $tree->children[$i]->from;
// position line in input file
$first_word_part = substr($words[$tree->children[$i]->from], 0, $tree->children[$i]->level + 1);
while (isset($words[$pos][$tree->children[$i]->level]) && $first_word_part == substr($words[$pos], 0, $tree->children[$i]->level + 1)) {
// add child
if (isset($words[$pos][$tree->children[$i]->level + 1]) && $c != $words[$pos][$tree->children[$i]->level + 1]) {
$c = $words[$pos][$tree->children[$i]->level + 1];
$tree->children[$i]->addChild($c, $pos);
}
// last symbol in word
if (!isset($words[$pos][$tree->children[$i]->level + 1])) {
$tree->children[$i]->last = true;
}
$pos++;
}
// iterate to each children
recurse($tree->children[$i]);
}
}
示例6: recurse
function recurse($dir)
{
echo "{$dir}\n";
foreach (glob("{$dir}/*") as $filename) {
if (is_dir($filename)) {
recurse($filename);
} elseif (eregi('\\.xml$', $filename)) {
//~ echo "$filename\n";
$file = file_get_contents($filename);
$file = preg_replace_callback('~(<!\\[CDATA\\[)(.*)(\\]\\]>)~sU', "callback_htmlentities", $file);
$file = preg_replace_callback('~(<!--)(.*)(-->)~sU', "callback_htmlentities", $file);
// isn't in one function as it can match !CDATA[[...-->
if ($GLOBALS["MODE"] == "escape") {
$file = preg_replace_callback('~<(' . $GLOBALS['GOOD_TAGS'] . ')( [^>]*)?>(.*)</\\1>~sU', "callback_make_value", $file);
} else {
// "unescape"
$file = str_replace("\r", "", $file);
// for Windows version of Aspell
$file = preg_replace_callback('~<(' . $GLOBALS['GOOD_TAGS'] . ')( [^>]*)? aspell="(.*)"/>~sU', "callback_make_contents", $file);
}
$fp = fopen($filename, "wb");
fwrite($fp, $file);
fclose($fp);
}
}
}
示例7: recurse
function recurse($path)
{
global $newpcre, $dirlen;
foreach (scandir($path) as $file) {
if ($file[0] === '.' || $file === 'CVS' || @substr_compare($file, '.lo', -3, 3) === 0 || @substr_compare($file, '.loT', -4, 4) === 0 || @substr_compare($file, '.o', -2, 2) === 0) {
continue;
}
$file = "{$path}/{$file}";
if (is_dir($file)) {
recurse($file);
continue;
}
echo "processing {$file}... ";
$newfile = $newpcre . substr($file, $dirlen);
if (is_file($tmp = $newfile . '.generic') || is_file($tmp = $newfile . '.dist')) {
$newfile = $tmp;
}
if (!is_file($newfile)) {
die("{$newfile} is not available any more\n");
}
// maintain file mtimes so that cvs doesnt get crazy
if (file_get_contents($newfile) !== file_get_contents($file)) {
copy($newfile, $file);
}
// always include the config.h file
$content = file_get_contents($newfile);
$newcontent = preg_replace('/#\\s*ifdef HAVE_CONFIG_H\\s*(.+)\\s*#\\s*endif/', '$1', $content);
if ($content !== $newcontent) {
file_put_contents($file, $newcontent);
}
echo "OK\n";
}
}
示例8: recurse
function recurse($ob)
{
foreach ($ob as $k => $v) {
if (is_array($v)) {
echo "<li>{$k}<ul>";
recurse($v);
echo "</ul></li>";
} else {
echo "<li>{$k}</li>";
}
}
}
示例9: recurse
function recurse($array, $array1)
{
foreach ($array1 as $key => $value) {
if (!isset($array[$key]) || isset($array[$key]) && !is_array($array[$key])) {
$array[$key] = array();
}
if (is_array($value)) {
$value = recurse($array[$key], $value);
}
$array[$key] = $value;
}
return $array;
}
示例10: recurse
function recurse($path, $dests)
{
if (empty($dests)) {
global $g_paths;
$key = implode(' > ', $path);
$g_paths[$key] = get_path_distance($path);
return;
}
foreach ($dests as $to => $distance) {
$new_path = $path;
array_push($new_path, $to);
recurse($new_path, remove_key($dests, $to));
}
}
示例11: array_replace_recursive
function array_replace_recursive($array, $array1)
{
// handle the arguments, merge one by one
$args = func_get_args();
$array = $args[0];
if (!is_array($array)) {
return $array;
}
for ($i = 1; $i < count($args); $i++) {
if (is_array($args[$i])) {
$array = recurse($array, $args[$i]);
}
}
return $array;
}
示例12: recurse
function recurse($it)
{
echo '<ul>';
for (; $it->valid(); $it->next()) {
if ($it->isDir() && !$it->isDot()) {
printf('<li class="dir">%s</li>', $it->current());
if ($it->hasChildren()) {
$bleh = $it->getChildren();
echo '<ul>' . recurse($bleh) . '</ul>';
}
} elseif ($it->isFile() and stripos($it->getFileName(), ".phps")) {
echo '<li class="file"><a href="' . getUrl($it->getPath() . "/" . $it->getFileName()) . '">' . $it->current() . '</a> (' . $it->getSize() . ' Bytes)</li>';
}
}
echo '</ul>';
}
示例13: recurse
function recurse($path, $callback)
{
$path = _realpath($path);
foreach (_scandir($path) as $file) {
if ($file == '.' or $file == '..') {
continue;
}
$realfile = _realpath("{$path}/{$file}");
if (_is_dir($realfile)) {
recurse($realfile, $callback);
} else {
$callback($realfile);
}
}
$callback($path);
}
示例14: recurse
function recurse($path)
{
global $AR, $needsUpgrade;
$dh = opendir($path);
$files = array();
$nlsFiles = array();
$dirs = array();
$objectID = pathToObjectID($path);
while (is_resource($dh) && false !== ($file = readdir($dh))) {
if ($file != "." && $file != "..") {
$f = $path . $file;
if (is_file($f) && $file[0] == '_') {
$files[] = $file;
} else {
if (is_dir($f) && $file != "CVS" && $file != ".svn") {
$dirs[] = $f . "/";
}
}
}
}
closedir($dh);
foreach ($files as $file) {
$info = parseFile($file);
$nlsFiles[$info['file']][$info['nls']] = $info;
}
unset($files);
foreach ($nlsFiles as $basefile => $nlsData) {
if (count($nlsData)) {
$needsUpgrade[$objectID] = '' . $objectID;
}
}
unset($nlsFiles);
foreach ($dirs as $dir) {
recurse($dir);
}
unset($dirs);
}
示例15: die
#!/usr/bin/php
<?php
if (php_sapi_name() !== 'cli') {
die('This must be run from the command line');
}
include 'functions.php';
if ($argc == 1) {
echo "Usage : {$argv[0]} [options] FILE ...\n";
}
$targets = array();
for ($i = 1; $i < $argc; $i++) {
$x = $argv[$i];
if ($x == '-html') {
$output_ext = '._html.luminous';
luminous::set('format', 'html');
luminous::set('max-height', -1);
} else {
$targets[] = $argv[$i];
}
}
if (empty($targets)) {
$targets = $default_target;
}
foreach ($targets as $t) {
recurse($t, 'generate');
}