コード例 #1
0
function reverse($string)
{
    $length = strlen($string);
    if ($length == 1) {
        echo $string;
    } else {
        echo reverse(substr($string, 1, $length)) . substr($string, 0, 1);
    }
}
コード例 #2
0
ファイル: reverse.php プロジェクト: eltonoliver/Algorithms
function reverse($str)
{
    if (strlen($str) < 2) {
        return $str;
    }
    $mid = (int) strlen($str) / 2;
    $lft = substr($str, 0, $mid);
    $rgt = substr($str, $mid);
    return reverse($rgt) . reverse($lft);
}
コード例 #3
0
ファイル: index.php プロジェクト: kutniyan/HomeTasks
function reverse($n)
{
    $num = $n % 10;
    $n = ($n - $num) / 10;
    if ($n <= 0) {
        return $num;
    } else {
        return reverse($n);
    }
}
コード例 #4
0
ファイル: base.php プロジェクト: 4johndoe/hexlet
function filter($list, $func)
{
    $iter = function ($list, $acc) use(&$iter, $func) {
        if ($list === null) {
            return reverse($acc);
        }
        $newAcc = $func(car($list)) ? cons(car($list), $acc) : $acc;
        return $iter(cdr($list), $newAcc);
    };
    return $iter($list, null);
}
コード例 #5
0
ファイル: 05.php プロジェクト: Dragomir89/ittalents_homeworks
 function reverse($number, $len)
 {
     if ($len == 0) {
         return '';
     }
     $len = strlen($number);
     $result = $number % 10;
     $number = (int) ($number / 10);
     $len--;
     $number = (string) $number;
     return $result . reverse($number, $len);
 }
コード例 #6
0
function LeftRotateString($string, $m)
{
    assert("is_string('{$string}')");
    assert("is_int({$m})");
    $len = mb_strlen($string, 'utf-8');
    $m %= $len;
    //求余数,减少移动长度大于字符串长度时的比较次数
    $head = reverse(mb_substr($string, 0, $m, 'utf-8'));
    //反转[0..m - 1],套用到上面举的例子中,就是X->X^T,即 abc->cba
    $tail = reverse(mb_substr($string, $m, $len, 'utf-8'));
    //反转[m..n - 1],例如Y->Y^T,即            def->fed
    return reverse($head . $tail);
    //反转[0..n - 1],即如整个反转,(X^TY^T)^T=YX,即 cbafed->defabc
}
コード例 #7
0
ファイル: register.php プロジェクト: ShefGena/homeworks
<?php

error_reporting(E_ALL);
header('Content-Type: text/html; charset=utf-8');
function reverse()
{
    if ($_POST) {
        $newMas = $_POST['userMessage'];
        $arr = explode(' ', $newMas);
        $cnt = array_count_values($arr);
        arsort($cnt);
        foreach ($cnt as $key => $a) {
            echo "{$key} - {$a}<br>";
        }
    }
}
reverse();
?>


コード例 #8
0
ファイル: takeRight.php プロジェクト: mpetrovich/dash
function takeRight($collection, $count = 1, $fromEnd = 0)
{
    $values = mapValues($collection);
    $reversed = reverse($values);
    return take($reversed, $count, $fromEnd);
}
コード例 #9
0
<?php

require_once 'array_functions.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['frequent'])) {
        $input = $_POST['test'];
        $duplicates = getDuplicates($input);
    } elseif (isset($_POST['reverse'])) {
        $input = $_POST['test'];
        reverse($input);
    } elseif (isset($_POST['largest'])) {
        $input = $_POST['test'];
        echo largestArray($input);
    } elseif (isset($_POST['sort'])) {
        $input = $_POST['test'];
        $input = sortArray($input);
    }
}
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Array Test</title>
  </head>
  <body>
    <?php 
if (isset($duplicates)) {
    echo $duplicates;
}
?>
コード例 #10
0
ファイル: 9.php プロジェクト: ABabiy/homeworks
 * Date: 07.02.2016
 * Time: 20:01
 */
/*
 9. Написать функцию, которая переворачивает строку. Было "abcde", должна выдать "edcba".
Ввод текста реализовать с помощью формы.
*/
//	$str = "sdfdf sssss ffffff hhhh dfgd";
$str = $_POST['comment'];
function reverse($str)
{
    $res1 = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
    krsort($res1);
    echo "Строка ВХОДЯЩАЯ" . "<br>";
    echo $str . "<br>";
    echo "=======================================" . "<br>";
    echo "Строка ИСХОДЯЩАЯ" . "<br>";
    echo $res2 = implode($res1);
}
reverse("{$str}");
?>
<center>
	<form action="9.php" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
		<input type="text" name="comment" size="40" id="num"
		       placeholder="Ввадите строку: ">
		<br>
		<br>
		<button type="submit">Отправить</button>
	</form>
</center>
コード例 #11
0
ファイル: list.php プロジェクト: tarsana/functional
/**
 * Returns the position/key of the last item satisfying the
 * predicate in the array or null if no such element is found.
 * ```php
 * findLastIndex(startsWith('b'), ['foo', 'bar', 'baz']); // 2
 * findLastIndex(startsWith('b'), ['a' => 'foo', 'b' => 'bar', 'c' => 'baz']); // 'c'
 * findLastIndex(startsWith('c'), ['foo', 'bar', 'baz']); // null
 * ```
 *
 * @signature (a -> Boolean) -> [a] -> Maybe(Number)
 * @signature (v -> Boolean) -> {k: v} -> Maybe(k)
 * @param  callable $predicate
 * @param  array $list
 * @return mixed
 */
function findLastIndex()
{
    $findLastIndex = function ($predicate, $list) {
        foreach (reverse(toPairs($list)) as $pair) {
            if ($predicate($pair[1])) {
                return $pair[0];
            }
        }
        return null;
    };
    return apply(curry($findLastIndex), func_get_args());
}
コード例 #12
0
<?php

if (!isset($argv)) {
    exit('The script must be run from the command line');
}
print 'Please provide an array of numbers to reverse: ';
$values = fgets(STDIN);
function reverse($input)
{
    $array = explode(' ', $input);
    if (!is_array($array)) {
        exit('Not an array.');
    }
    $reverse = array_reverse($array);
    print_r($reverse);
}
echo 'Your array has been reversed!' . reverse($values);
コード例 #13
0
ファイル: generator_with_keys.php プロジェクト: badlamer/hhvm
<?php

function reverse(array $array)
{
    end($array);
    while (null !== ($key = key($array))) {
        (yield $key => current($array));
        prev($array);
    }
}
$array = ['foo' => 'bar', 'bar' => 'foo'];
foreach (reverse($array) as $key => $value) {
    echo $key, ' => ', $value, "\n";
}
コード例 #14
0
ファイル: index.php プロジェクト: plasticine/rivet
        }
    }
    return Template::render('contacts/index.html', array('form' => $form, 'contacts' => DB::model('Contacts')->order_by('date', 'desc')->all()));
}), new Route('/contact', 'contact', function ($request) {
    $form = new Form(array(new TextField('name', array('required' => true), array('placeholder' => 'Your Name')), new EmailField('email', array('required' => true), array('placeholder' => 'Your Email')), new URLField('address', array('required' => false), array('placeholder' => 'http://')), new TextField('subject', array('required' => true), array('placeholder' => 'Subject')), new TextBoxField('message', array('required' => true))));
    $test = '"hello world..." My AMPS are really good-lookin\' & my type is clean!';
    if ($request['method'] == 'post') {
        echo $request['post']['message'] . "<br>";
        $form = $form($request['post']);
        if ($form->is_valid()) {
            echo $form['message'] . "<br>";
        }
    }
    return Template::render('contact/index.html', array('form' => $form, 'test' => $test));
}), new Route('/journal/{?int:page}', 'journal', function ($request, $page = 0) {
    return Template::render('journal/index.html', array('articles' => DB::model('Articles')->order_by('date', 'desc')->all()));
}), new Route('/journal/{slug:article}', 'article', function ($request, $article) {
    $article = DB::model('Articles')->where('slug', $article)->exec();
    return Template::render('journal/article.html', array('article' => $article[0], 'tags' => DB::model('Tag')->all()));
}), new Route('/journal/{slug:tag}', 'tag', function ($request, $tag) {
    return Template::render('journal/tag.html', array('tag' => $tag));
}), new Route('/foo', 'foo', function ($request) {
    return redirect(reverse('bar'));
}), new Route('/bar', 'bar', function ($request) {
    return 'You were redirected from Foo!';
}), new Route('/404', '404', function ($request) {
    return notfound();
}), new Route('/500', '500', function ($request) {
    return error();
})));
echo Rivet::dispatch();
コード例 #15
0
ファイル: index.php プロジェクト: kutniyan/HomeTasks
function reverse($n)
{
    if ($n >= 1) {
        echo $n % 10;
        echo '&nbsp';
        $n = ($n - $n % 10) / 10;
        reverse($n);
    }
    return;
}
コード例 #16
0
ファイル: findLast.php プロジェクト: mpetrovich/dash
function findLast($collection, $predicate)
{
    $values = mapValues($collection);
    $reversed = reverse($values);
    return find($reversed, $predicate);
}
コード例 #17
0
ファイル: compose.php プロジェクト: akamon/phunctional
/**
 * Takes a set of functions and returns another that is the composition of those `$fns`.
 * The result from the first function execution is used in the second function, etc.
 *
 * @since 0.1
 *
 * @param callable[] $fns functions to be composed
 *
 * @return mixed
 */
function compose(...$fns)
{
    return pipe(...reverse($fns));
}
コード例 #18
0
 protected function init_apps()
 {
     //INSTALLED_APPS uygulamalar için gerekli modülleri yükle
     $installedApps = pjango_ini_get('INSTALLED_APPS');
     $_installedApps = array();
     $languageCode = pjango_ini_get('LANGUAGE_CODE');
     $databases = pjango_ini_get('DATABASES');
     foreach ($installedApps as $app) {
         $appPath = reverse($app);
         $classLoader = new ClassLoader($app);
         $classLoader->register();
         if ($appPath) {
             $_installedApps[$app]['name'] = $app;
             $_installedApps[$app]['full_path'] = $appPath;
             if (is_dir($appPath . '/Models')) {
                 $_installedApps[$app]['model_path'] = $appPath . '/Models';
                 if ($databases) {
                     $this->_loadedModels[$app] = \Doctrine::loadModels($appPath . '/Models');
                 }
             }
             if (is_dir($appPath . '/Templates')) {
                 $_installedApps[$app]['template_path'] = $appPath . '/Templates/';
                 $GLOBALS['SETTINGS']['TEMPLATE_DIRS'][] = $appPath . '/Templates/';
             }
             $tmpPath = $appPath . '/Locale/' . $languageCode . '/LC_MESSAGES/messages.po';
             if (is_file($tmpPath)) {
                 $_installedApps[$app]['lang_file'] = $tmpPath;
                 $GLOBALS['SETTINGS']['LOCALE_PATHS'][] = $tmpPath;
             }
             $tmpPath = $appPath . '/Admin.php';
             if (is_file($tmpPath)) {
                 $_installedApps[$app]['admin_file'] = $tmpPath;
                 require_once $tmpPath;
             }
             $tmpPath = $appPath . '/Templatetags.php';
             if (is_file($tmpPath)) {
                 $_installedApps[$app]['templatetags'] = $tmpPath;
                 require_once $tmpPath;
             }
             $tmpPath = $appPath . '/Forms.php';
             if (is_file($tmpPath)) {
                 $_installedApps[$app]['forms'] = $tmpPath;
                 require_once $tmpPath;
             }
         }
     }
     $tmpPath = SITE_PATH . '/locale/' . $languageCode . '/LC_MESSAGES/messages.po';
     $GLOBALS['SETTINGS']['LOCALE_PATHS'][] = $tmpPath;
     $isDebug = pjango_ini_get('DEBUG');
     $cacheFile = sprintf('%s/cache/lang_%s_%s.cache', SITE_PATH, SITE_ID, $lng);
     Pjango\PTrans::init($cacheFile, $isDebug);
     pjango_ini_set('_INSTALLED_APPS', $_installedApps);
 }
コード例 #19
0
ファイル: path.php プロジェクト: antoniomachine/bigml-php
function merge_numeric_rules($list_of_predicates, $fields, $label = 'name', $missing_flag = null)
{
    /* Summarizes the numeric predicates for the same field */
    $minor = array(null, -INF);
    $major = array(null, INF);
    $equal = null;
    foreach ($list_of_predicates as $predicate) {
        if (substr($predicate->operator, 0, 1) == ">" && $predicate->value > $minor[1]) {
            $minor = array($predicate, $predicate->value);
        }
        if (substr($predicate->operator, 0, 1) == "<" && $predicate->value < $major[1]) {
            $major = array($predicate, $predicate->value);
        }
        if (in_array(substr($predicate->operator, 0, 1), array("!", "=", "/", "i"))) {
            $equal = $predicate;
            break;
        }
    }
    if (!is_null($equal)) {
        return $equal->to_rule($fields, $label, $missing_flag);
    }
    $rule = "";
    $field_id = $list_of_predicates[0]->field;
    $name = $fields->{$field_id}->{$label};
    if (!is_null($minor[0]) && !is_null($major[0])) {
        $predicate = $minor[0];
        $value = $minor[1];
        $rule = $value . " " . reverse($predicate->operator) . " " . $name;
        $predicate = $major[0];
        $value = $major[1];
        $rule = $rule . " " . $predicate->operator . " " . $value . " ";
        if (!is_null($missing_flag)) {
            $rule = $rule . " or missing";
        }
    } else {
        $predicate = !is_null($minor[0]) ? $minor[0] : $major[0];
        $rule = $predicate->to_rule($fields, $label, $missing_flag);
    }
    return $rule;
}
コード例 #20
0
/**
 * @param string $string_
 * @param integer $length_
 * @param string $append_
 * @param string $truncateAtCharacter_
 *
 * @return string
 */
function truncate($string_, $length_, $append_ = null, $truncateAtCharacter_ = null, $style_ = LIBSTD_STR_TRUNCATE_END)
{
    if ($length_ >= mb_strlen($string_)) {
        return $string_;
    }
    if (0 < ($style_ & LIBSTD_STR_TRUNCATE_REVERSE)) {
        $string_ = reverse($string_);
        $string = mb_substr($string_, 0, $length_);
        if (null === $truncateAtCharacter_) {
            return $append_ . reverse($string);
        }
        $truncatePos = mb_strpos($string_, $truncateAtCharacter_, $length_);
        return $append_ . reverse($string . mb_substr($string_, $length_, $truncatePos - $length_));
    }
    $string = mb_substr($string_, 0, $length_);
    if (null === $truncateAtCharacter_) {
        return $string . $append_;
    }
    $truncatePos = mb_strpos($string_, $truncateAtCharacter_, $length_);
    return $string . mb_substr($string_, $length_, $truncatePos - $length_) . $append_;
}
コード例 #21
0
ファイル: data_to_db.php プロジェクト: bestbud/project
    $data[$i++] = $spot;
}
if (($length = count($data)) != $nfft) {
    echo "length error!";
}
//后半数据放到前面
function reverse(array $data)
{
    //数组前后半段数据交换
    $reverse_data = array();
    for ($j = count($data) / 2, $i = 0; $j < count($data); $j++) {
        $reverse_data[$i++] = $data[$j];
    }
    for ($j = 0, $harf_len = count($data) / 2; $j < count($data) / 2; $j++) {
        $reverse_data[$harf_len++] = $data[$j];
    }
    return $reverse_data;
}
$data = reverse($data);
echo $data_txt = implode(',', $data);
//数组转字符串
echo "<br>";
//存入数据库
include "../../lib/db.php";
error_reporting(E_ALL & ~E_NOTICE);
$sql = "insert into `spectrum` (`f0`,`bw`,`g`,`nfft`,`data`) values ('{$f0}','{$bw}','{$g}','{$nfft}','{$data_txt}')";
if ($query = mysql_query($sql)) {
    echo "成功存入数据库";
} else {
    echo "lose";
}
コード例 #22
0
    $string = htmlentities($_POST['user-input']);
    $selection = htmlentities($_POST['option']);
    $result = '';
    switch ($selection) {
        case 'palindrome':
            if (isPalindrome($string)) {
                $result = "{$string} is a palindrome!";
            } else {
                $result = "{$string} is not a palindrome!";
            }
            break;
        case "shuffle":
            $result = str_shuffle($string);
            break;
        case "reverse":
            $result = reverse($string);
            break;
        case "hash":
            $result = password_hash($string, PASSWORD_BCRYPT);
            break;
        case "split":
            $result = preg_replace('/[\\P{L}]+/u', '', $string);
            $result = implode(' ', preg_split('//u', $result, -1, PREG_SPLIT_NO_EMPTY));
            break;
        default:
            $result = 'Unknown error occurred!';
    }
}
?>

<!DOCTYPE html>
コード例 #23
0
ファイル: functions.php プロジェクト: Savio1998/hello-world
?>
  <style>
      .text{
          margin-left: 20px;
          padding: 20px;
      }
  </style>
  </head>
  <body>
      <div class="text">
  <?php 
$a = 6;
//$s = "Hallo draai mij om";
?>
<h3><?php 
reverse($a);
?>
</h3><?php 
celFahren($a);
divisible($a);
if (divisible($a)) {
    echo "Ja " . $a . " is deel baar door 3";
} else {
    echo "Nee je kan " . $a . " niet door 3 delen";
}
function celFahren($c)
{
    $f = $c * 9 / 5 + 32;
    echo "°" . $c . " Celcius = °" . $f . " Fahrenheit<br>";
}
function divisible($d)
コード例 #24
0
<?php

$word = "alphabet";
//google
if (!empty($word)) {
    if (uniqueCharacters($word)) {
        echo "This word '{$word}' has only unique characters." . "\n";
    } else {
        echo "This word '{$word}' has atleast one duplicate character." . "\n";
    }
    $distinctChars = removeDuplicateCharacters($word);
    echo "Removed duplicate characters from word '{$word}' & result is '{$distinctChars}'" . "\n";
    $reverse = reverse($word);
    echo "Reverse of word '{$word}' is '{$reverse}'" . "\n";
} else {
    // defensive
    echo "Empty word passed. Not much we can do :) ." . "\n";
}
function uniqueCharacters($word)
{
    if (empty($word)) {
        // defensive
        return false;
    }
    // length of the given word
    $wordLength = strlen($word);
    if ($wordLength == 1) {
        // special case
        return true;
    }
    // associative array which will maintain mapping of a char and number