function iterate(RecursiveIterator $iterator)
{
    foreach ($iterator as $value) {
        if ($iterator->hasChildren()) {
            iterate($iterator->getChildren());
            continue;
        }
        echo $value, PHP_EOL;
    }
}
예제 #2
0
function detect_cliques($graph)
{
    global $c1, $c2, $searched, $s, $k;
    $max = 0;
    $cliques = array();
    $incl = array();
    list($graph, $max, $cliques, $incl) = iterate($graph, $graph->nodes, $max, $cliques);
    foreach ($cliques as $i => $c) {
        if (count($c) == $max) {
            $largest = $c;
        }
    }
    return array($max, $cliques, $largest);
}
예제 #3
0
function iterate($path)
{
    $array_dir = @scandir($path);
    @asort($array_dir);
    foreach ($array_dir as $value) {
        if (is_dir($value) && strcmp($value, ".") && strcmp($value, "..")) {
            if (!is_dir_empty($value)) {
                chdir($value);
                parse();
                iterate(getcwd(), $value);
                chdir("..");
            }
        }
    }
}
예제 #4
0
/**
 * iterate over the config xml
 *
 * @param SimpleXmlIterator $iterator  xml iterator
 * @param string            $parentKey parent of the current value of the iterator
 *
 * @return void
 */
function iterate($iterator, $parentKey)
{
    $db = Database::singleton();
    for ($iterator->rewind(); $iterator->valid(); $iterator->next()) {
        $current = $iterator->current();
        $name = $iterator->key();
        if ($iterator->hasChildren()) {
            iterate($current, $name);
        } else {
            // Else it is a leaf
            // If a key by that name exists, get its ID
            $configID = $db->pselectone("SELECT ID \n                 FROM ConfigSettings \n                 WHERE Name=:name", array('name' => $name));
            // If the key already exists
            if (!empty($configID)) {
                $dbParentKey = $db->pselectone("SELECT Name \n                     FROM ConfigSettings \n                     WHERE ID=(SELECT Parent FROM ConfigSettings WHERE Name=:name)", array('name' => $name));
                if ($parentKey == $dbParentKey) {
                    // Insert into the DB
                    processLeaf($name, $current, $configID);
                }
            }
        }
    }
}
예제 #5
0
        }
        if ($current->text() == 'Шымкент') {
            $current->replyDropDown("Выберите:", $firstLevel);
        }
        if ($current->text() == 'Услуги') {
            $current->replyDropDown("Выберите:", $secondLevel);
        }
        if ($current->text() == 'Акции') {
            $current->reply('Уважаемые дамы и господа!' . '%0A' . 'АЛМА-ТВ запускает новогоднюю акцию, которая позволяет сэкономить до 10 000 тенге.' . '%0A' . 'При внесении предоплаты за 12 и более месяцев, предоставляются скидки:' . '%0A' . '-     на пакеты «TV100+» и «Антенна80+» - скидка 18%' . '%0A' . '-      на пакеты «TVMAX» и «AntennaMAX» -скидка в 24%.' . '%0A' . 'Специальное предложение, действует до 31 января 2016 года.');
        }
        if ($current->text() == 'Адреса, контакты') {
            $current->replyDropDown("Выберите:", $secondLevel);
        }
        if ($current->text() == 'Отправить запрос о неполадках') {
            $current->replyDropDown("Выберите:", $secondLevel);
        }
        if ($current->text() == 'Приложения АЛМА-ТВ') {
            $current->reply('Приложение “Alma TV” позволяет получить мгновенный доступ к балансу Вашего счёта, телепрограмме и многому другому. Дополнительно, у пользователя есть возможность отправки заявок на подключение или ремонт в несколько простых шагов.
        Для проверки баланса требуется быть абонентом компании «АЛМА-ТВ», остальные функции доступны всем пользователям. Возможность управления Вашим счётом и множество иных функций появятся в следующих версиях приложения.' . '%0A' . 'Для скачивания приложения ALMA-TV на Android перейдите по ссылке: ' . '%0A' . 'Приложение "TV BOX". Смотрите любимые передачи, как на телевизоре, так и на мобильных устройствах.
        Сортируйте каналы по жанрам, ставьте видео на паузу и перематывайте, выбирайте звуковую дорожку и качество изображения. Подробнее об этих и других функциях TV Box на сайте tv-box.kz' . '%0A' . 'Для скачивания приложения TV BOX на Ваше мобильное устройство, пройдите по ссылкам:', $secondLevel);
        }
        echo "==> Message text {$current->text()} \n\r";
    }
    echo "==> Setup new offset {$offset}\n\r";
    return $offset;
}
while (true) {
    $offset = iterate($offset);
    echo "==> Sleep 3 seconds \n\r";
    sleep(3);
}
예제 #6
0
파일: bug38347.php 프로젝트: badlamer/hhvm
<?php

function iterate($xml)
{
    print_r($xml);
    foreach ($xml->item as $item) {
        echo "This code will crash!";
    }
}
$xmlstr = "<xml><item>Item 1</item><item>Item 2</item></xml>";
$xml = simplexml_load_string($xmlstr);
iterate($xml->unknown);
echo "Done\n";
예제 #7
0
파일: day18.php 프로젝트: MaMa/adventofcode
    foreach ($ngrid as $y => $row) {
        foreach ($row as $x => $n) {
            if ($grid[$y][$x]) {
                //A light which is on stays on when 2 or 3 neighbors are on, and turns off otherwise.
                $newGrid[$y][$x] = $n == 2 || $n == 3;
            } else {
                //A light which is off turns on if exactly 3 neighbors are on, and stays off otherwise.
                $newGrid[$y][$x] = $n == 3;
            }
        }
    }
    if (PART_2) {
        return stuckLights($newGrid);
    }
    return $newGrid;
}
//loop
for ($i = 0; $i < $steps; $i++) {
    $grid = iterate($grid);
}
//result
$count = 0;
foreach ($grid as $y => $row) {
    foreach ($row as $x => $on) {
        if ($on) {
            $count++;
        }
    }
}
printGrid($grid);
print "Lights lit: {$count}\n";
    function valid()
    {
        echo __METHOD__ . "; ";
        return parent::valid();
    }
    function rewind()
    {
        echo __METHOD__ . "; ";
        return parent::rewind();
    }
    function nextElement()
    {
        echo __METHOD__ . "; ";
        return parent::nextElement();
    }
}
$arr = array('Zero', 'name' => 'Adil', 'address' => array('city' => 'Dubai', 'tel' => array('int' => 971, 'tel' => 12345487)), '' => 'nothing');
function iterate($it, $depth)
{
    if ($depth) {
        $it->setMaxDepth($depth);
    }
    foreach ($it as $k => $v) {
        echo "[{$k}];\n";
    }
}
iterate(new X(new RecursiveArrayIterator($arr), RecursiveIteratorIterator::LEAVES_ONLY), false);
iterate(new X(new RecursiveArrayIterator($arr), RecursiveIteratorIterator::SELF_FIRST), false);
iterate(new X(new RecursiveArrayIterator($arr), RecursiveIteratorIterator::CHILD_FIRST), false);
iterate(new X(new RecursiveArrayIterator($arr), RecursiveIteratorIterator::CHILD_FIRST), 1);
예제 #9
0
파일: day10.php 프로젝트: MaMa/adventofcode
Your puzzle input is 3113322113.
*/
function iterate($in)
{
    $res = '';
    $last = null;
    $count = 0;
    $chars = str_split($in);
    foreach (str_split($in) as $char) {
        if (is_null($last)) {
            $last = $char;
            $count++;
        } elseif ($char === $last) {
            $count++;
        } else {
            $res .= strval($count) . strval($last);
            $last = $char;
            $count = 1;
        }
    }
    $res .= strval($count) . strval($last);
    return $res;
}
$in = '3113322113';
for ($i = 0; $i < 50; $i++) {
    $res = iterate($in);
    //print ("${in} -> ${res}\n");
    $in = $res;
}
print "Res length: " . strlen($res) . "\n";
예제 #10
0
iterate($q->answers, function ($the) {
    ?>
            <img src="{{ $the->writer->avatar }}" width="16" height="16"/>
        <?php 
});
?>
        <?php 
iterate($q->comments, function ($the) {
    ?>
            <img src="{{ $the->writer->avatar }}" width="16" height="16"/>
        <?php 
});
?>
        @foreach ($q->answers as $a)
        <?php 
iterate($a->comments, function ($the) {
    ?>
            <img src="{{ $the->writer->avatar }}" width="16" height="16"/>
        <?php 
});
?>
        @endforeach
        <?php 
clear();
?>
        <h4>{{ $q->title }}</h4>
    </a>
    @endforeach
</ul>

{!! $qs->links() !!}
예제 #11
0
파일: test.php 프로젝트: DaylixX/ActionFPS
<?php

$stuff = file_get_contents("php://input");
$arr = explode("\n", $stuff);
$state = json_decode(array_shift($arr), false);
function iterate($state, $game)
{
    if (!$state) {
        $state = new stdClass();
        $state->seen = [];
    }
    if (in_array($game->id, $state->seen)) {
        return $state;
    }
    $state->seen[] = $game->id;
    return $state;
}
foreach ($arr as $game_json) {
    $game = json_decode($game_json, false);
    $state = iterate($state, $game);
}
echo json_encode($state, false);