当前位置: 首页>>代码示例>>PHP>>正文


PHP range函数代码示例

本文整理汇总了PHP中range函数的典型用法代码示例。如果您正苦于以下问题:PHP range函数的具体用法?PHP range怎么用?PHP range使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了range函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Generate

 function Generate($level)
 {
     if ($level <= 3) {
         $numbers = range(1, 5);
         $set_size = rand(3, 4);
         $subset_size = 2;
     } elseif ($level <= 6) {
         $numbers = range(1, 10);
         $set_size = rand(4, 6);
         $subset_size = rand(2, 3);
     } else {
         $numbers = range(1, 20);
         $set_size = rand(7, 10);
         $subset_size = rand(3, 4);
     }
     $set = $this->Set($numbers, $set_size);
     $subset = NumText($subset_size);
     // // Original exercise
     // $set_size = 5;
     // $set = [2,3,5,7,11];
     // $subset = 'kettő';
     $question = 'Hány darab ' . ($subset == 'kettő' ? 'két' : $subset) . 'elemű részhalmaza van ' . The($set[0]) . ' $\\{' . implode(";", $set) . '\\}$ halmaznak?';
     $correct = binomial_coeff(count($set), $subset_size);
     $hints = $this->Hints($set_size, $subset_size);
     $solution = '$' . $correct . '$';
     return array('question' => $question, 'correct' => $correct, 'solution' => $solution, 'hints' => $hints);
 }
开发者ID:zsebtanar,项目名称:zsebtanar_v4,代码行数:27,代码来源:Reszhalmazok.php

示例2: run

 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 50) as $index) {
         User::create(['github_id' => $index, 'github_url' => $faker->url(), 'city' => $faker->city(), 'name' => $faker->userName(), 'twitter_account' => $faker->userName(), 'company' => $faker->userName(), 'personal_website' => $faker->url(), 'signature' => $faker->sentence(), 'introduction' => $faker->sentence(), 'email' => $faker->email()]);
     }
 }
开发者ID:bobken,项目名称:phphub,代码行数:7,代码来源:UserTableSeeder.php

示例3: run

 public function run()
 {
     $faker = Factory::create();
     foreach (range(1, 10) as $index) {
         Category::create(['name' => $faker->firstName, 'description' => $faker->text(130), 'active' => $faker->boolean(85)]);
     }
 }
开发者ID:Tisho84,项目名称:laravel-work,代码行数:7,代码来源:CategoriesTableSeeder.php

示例4: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     foreach (range(1, 200) as $index) {
         DB::table('parts')->insert(['description' => $faker->realText(100), 'cost' => $faker->randomFloat(2, 1, 1000)]);
     }
 }
开发者ID:robbiepaul,项目名称:nodendb,代码行数:12,代码来源:PartsSeeder.php

示例5: run

 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Product::create(['product_name' => $faker->word, 'details' => $faker->paragraph, 'picture' => 'uploads/products/1default.jpg', 'min_price' => $faker->randomDigit, 'max_price' => $faker->randomDigitNotNull, 'crop_id' => 1, 'location' => $faker->country, 'expiry_date' => $faker->date('Y--m-d')]);
     }
 }
开发者ID:talha08,项目名称:Farmer-Bazar,代码行数:7,代码来源:ProductsTableSeeder.php

示例6: configure

 protected function configure()
 {
     $this->addOption('date_widget', DateField::CHOICE, self::$dateWidgets);
     $this->addOption('time_widget', TimeField::CHOICE, self::$timeWidgets);
     $this->addOption('type', self::DATETIME, self::$types);
     $this->addOption('date_pattern');
     $this->addOption('with_seconds', false);
     $this->addOption('years', range(date('Y') - 5, date('Y') + 5));
     $this->addOption('months', range(1, 12));
     $this->addOption('days', range(1, 31));
     $this->addOption('hours', range(0, 23));
     $this->addOption('minutes', range(0, 59));
     $this->addOption('seconds', range(0, 59));
     $this->addOption('data_timezone', 'UTC');
     $this->addOption('user_timezone', 'UTC');
     $this->addOption('date_format', DateField::MEDIUM, self::$dateFormats);
     $this->add(new DateField('date', array('type' => DateField::RAW, 'widget' => $this->getOption('date_widget'), 'format' => $this->getOption('date_format'), 'data_timezone' => $this->getOption('user_timezone'), 'user_timezone' => $this->getOption('user_timezone'), 'years' => $this->getOption('years'), 'months' => $this->getOption('months'), 'days' => $this->getOption('days'), 'pattern' => $this->getOption('date_pattern'))));
     $this->add(new TimeField('time', array('type' => TimeField::RAW, 'widget' => $this->getOption('time_widget'), 'data_timezone' => $this->getOption('user_timezone'), 'user_timezone' => $this->getOption('user_timezone'), 'with_seconds' => $this->getOption('with_seconds'), 'hours' => $this->getOption('hours'), 'minutes' => $this->getOption('minutes'), 'seconds' => $this->getOption('seconds'))));
     if ($this->getOption('type') == self::STRING) {
         $this->setNormalizationTransformer(new ReversedTransformer(new DateTimeToStringTransformer(array('input_timezone' => $this->getOption('data_timezone'), 'output_timezone' => $this->getOption('data_timezone')))));
     } else {
         if ($this->getOption('type') == self::TIMESTAMP) {
             $this->setNormalizationTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer(array('input_timezone' => $this->getOption('data_timezone'), 'output_timezone' => $this->getOption('data_timezone')))));
         }
     }
     $this->setValueTransformer(new DateTimeToArrayTransformer(array('input_timezone' => $this->getOption('data_timezone'), 'output_timezone' => $this->getOption('user_timezone'))));
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:27,代码来源:DateTimeField.php

示例7: getIterator

 /**
  * @param  number $step the interval amount
  * @return ArrayIterator
  */
 public function getIterator($step = self::DEFAULT_STEP)
 {
     if (!is_numeric($step)) {
         throw new InvalidArgumentException('A numeric (int, float) step value is required');
     }
     return new ArrayIterator(range($this->start, $this->end, $step));
 }
开发者ID:texdc,项目名称:range,代码行数:11,代码来源:AbstractNumericRange.php

示例8: run

 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Stockpackage::create([]);
     }
 }
开发者ID:yanguanglan,项目名称:sz,代码行数:7,代码来源:StockpackagesTableSeeder.php

示例9: json_encode

 function json_encode($data)
 {
     if (is_array($data)) {
         $ret = array();
         // OBJECT
         if (array_keys($data) !== range(0, count($data) - 1)) {
             foreach ($data as $key => $val) {
                 $ret[] = kcfinder_json_string_encode($key) . ':' . json_encode($val);
             }
             return "{" . implode(",", $ret) . "}";
             // ARRAY
         } else {
             foreach ($data as $val) {
                 $ret[] = json_encode($val);
             }
             return "[" . implode(",", $ret) . "]";
         }
         // BOOLEAN OR NULL
     } elseif (is_bool($data) || $data === null) {
         return $data === null ? "null" : ($data ? "true" : "false");
     } elseif (is_float($data)) {
         return rtrim(rtrim(number_format($data, 14, ".", ""), "0"), ".");
     } elseif (is_int($data)) {
         return $data;
     }
     // STRING
     return kcfinder_json_string_encode($data);
 }
开发者ID:jacobDaeHyung,项目名称:laravel_bus_reservation,代码行数:28,代码来源:autoload.php

示例10: testInvalidChars

 public function testInvalidChars()
 {
     $filter = new \r8\Filter\Alpha();
     $this->assertEquals("", $filter->filter('1234567890'));
     $this->assertEquals("", $filter->filter('!"#$%&\'()*+,-/:;<=>?@[\\]^`{|}~'));
     $this->assertEquals("", $filter->filter(implode("", array_map("chr", range(127, 255)))));
 }
开发者ID:Nycto,项目名称:Round-Eights,代码行数:7,代码来源:Alpha.php

示例11: getProfile

 protected function getProfile()
 {
     $profile = new Twig_Profiler_Profile();
     $index = new Twig_Profiler_Profile('index.twig', Twig_Profiler_Profile::TEMPLATE);
     $profile->addProfile($index);
     $body = new Twig_Profiler_Profile('embedded.twig', Twig_Profiler_Profile::BLOCK, 'body');
     $body->leave();
     $index->addProfile($body);
     $embedded = new Twig_Profiler_Profile('embedded.twig', Twig_Profiler_Profile::TEMPLATE);
     $included = new Twig_Profiler_Profile('included.twig', Twig_Profiler_Profile::TEMPLATE);
     $embedded->addProfile($included);
     $index->addProfile($embedded);
     $included->leave();
     $embedded->leave();
     $macro = new Twig_Profiler_Profile('index.twig', Twig_Profiler_Profile::MACRO, 'foo');
     $macro->leave();
     $index->addProfile($macro);
     $embedded = clone $embedded;
     $index->addProfile($embedded);
     $a = range(1, 1000);
     $embedded->leave();
     $profile->leave();
     usleep(5000);
     $index->leave();
     return $profile;
 }
开发者ID:tahermarkos,项目名称:Transport,代码行数:26,代码来源:AbstractTest.php

示例12: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $newWidth = $input->getOption('size');
     $inverted = filter_var($input->getOption('inverted'), FILTER_VALIDATE_BOOLEAN);
     $chars = $this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('AsciiArtAnalyzerBundle:Char')->getAllChars($inverted);
     $manager = new ImageManager(['driver' => 'imagick']);
     $image = $manager->make("files/image.jpg");
     /**
      * @var \Imagick $imagick
      */
     $imagick = $image->resize($newWidth, $newWidth / $image->getWidth() * $image->getHeight())->getCore();
     list($width, $height) = array_values($imagick->getImageGeometry());
     $ascii = [];
     foreach (range(1, $height) as $y) {
         $string = "";
         foreach (range(1, $width) as $x) {
             $rgb = $imagick->getImagePixelColor($x, $y)->getColor();
             $pixelLuminosity = intval(($rgb['r'] + $rgb['g'] + $rgb['b']) / 3);
             $string .= $chars[$pixelLuminosity];
         }
         array_push($ascii, $string);
     }
     if ($input->getOption('output') == 'image') {
         $this->asciiToImage($ascii, $inverted);
     } else {
         echo implode("\n", $ascii);
     }
 }
开发者ID:philippecarle,项目名称:AsciiArt,代码行数:31,代码来源:Image2AsciiCommand.php

示例13: testComplexValues

 function testComplexValues()
 {
     $fields = array('timestamp' => 0, 'priority' => 42, 'priorityName' => 'bar');
     $f = new Simple();
     $fields['message'] = 'Foo';
     $line = $f->format($fields);
     $this->assertContains($fields['message'], $line);
     $fields['message'] = 10;
     $line = $f->format($fields);
     $this->assertContains($fields['message'], $line);
     $fields['message'] = 10.5;
     $line = $f->format($fields);
     $this->assertContains($fields['message'], $line);
     $fields['message'] = true;
     $line = $f->format($fields);
     $this->assertContains('1', $line);
     $fields['message'] = fopen('php://stdout', 'w');
     $line = $f->format($fields);
     $this->assertContains('Resource id ', $line);
     fclose($fields['message']);
     $fields['message'] = range(1, 10);
     $line = $f->format($fields);
     $this->assertContains('array', $line);
     $fields['message'] = new SimpleTest_TestObject1();
     $line = $f->format($fields);
     $this->assertContains($fields['message']->__toString(), $line);
     $fields['message'] = new SimpleTest_TestObject2();
     $line = $f->format($fields);
     $this->assertContains('object', $line);
 }
开发者ID:rexmac,项目名称:zf2,代码行数:30,代码来源:SimpleTest.php

示例14: compile_array

 function compile_array($options)
 {
     if (self::check($this->from_num) && self::check($this->to_num) && abs($this->from_num - $this->to_num) <= 20) {
         $range = range($this->from_num, $this->to_num);
         if ($this->exclusive) {
             array_pop($range);
         }
         return '[' . implode(', ', $range) . ']';
     }
     $idt = $this->tab . TAB;
     $i = $options['scope']->free_variable('i');
     $result = $options['scope']->free_variable('results');
     $pre = "\n{$idt}{$result} = [];";
     if (self::check($this->from_num) && self::check($this->to_num)) {
         $options['index'] = $i;
         $body = $this->compile_node($options);
     } else {
         $vars = "{$i} = {$this->from_c}" . ($this->to_c !== $this->to_var ? ", {$this->to_c}" : '');
         $cond = "{$this->from_var} <= {$this->to_var}";
         $body = "var {$vars}; {$cond} ? {$i} <{$this->equals} {$this->to_var} : {$i} >{$this->equals} {$this->to_var}; {$cond} ? {$i}++ : {$i}--";
     }
     $post = "{ {$result}.push({$i}); }\n{$idt}return {$result};\n{$options['indent']}";
     $has_args = function ($node) {
         return $node->contains(function ($n) {
             return $n instanceof yy_Literal && $n->value === 'arguments' && !$n->as_key;
         });
         return FALSE;
     };
     $args = '';
     if ($has_args($this->from) || $has_args($this->to)) {
         $args = ', arguments';
     }
     return "(function() {{$pre}\n{$idt}for ({$body}){$post}}).apply(this{$args})";
 }
开发者ID:robin7788,项目名称:hrmtest,代码行数:34,代码来源:Range.php

示例15: changePen

 /**
  * Changes the pen of the plotter.
  *
  * @param int $pen
  * @return $this
  */
 public function changePen(int $pen)
 {
     if (!in_array($pen, range(0, 6))) {
         throw new \InvalidArgumentException(sprintf('[%d] is not a valid Pen.', $pen));
     }
     return $this->pushCommand(sprintf('P%d;', $pen));
 }
开发者ID:nielsiano,项目名称:dmpl-builder,代码行数:13,代码来源:DmplBuilder.php


注:本文中的range函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。