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


PHP array_product函数代码示例

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


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

示例1: product

 /**
  * Calculate the product of values in an array
  * 
  * @param array $array
  * @return int
  */
 public function product($array)
 {
     if (!isset($array)) {
         return null;
     }
     return array_product((array) $array);
 }
开发者ID:GulKhan,项目名称:twig-extensions,代码行数:13,代码来源:ArrayExtension.php

示例2: factorial

function factorial($num)
{
    if ($num == 0) {
        return 1;
    }
    return array_product(range(1, $num));
}
开发者ID:keune,项目名称:euler-solutions,代码行数:7,代码来源:functions.php

示例3: calculateRibbon

 public function calculateRibbon($dimension)
 {
     $dimension = $this->dimensionsToArray($dimension);
     asort($dimension, SORT_NUMERIC);
     $smallest = array_values(array_slice($dimension, 0, 2));
     return $smallest[0] * 2 + $smallest[1] * 2 + array_product($dimension);
 }
开发者ID:Helfull,项目名称:Advent-of-code,代码行数:7,代码来源:Day2.php

示例4: process

function process($input, $compartments = 3)
{
    for ($i = 0, $minFg = 0, $minQe = 0, $perGroup = array_sum($input) / $compartments; $i < 100;) {
        for ($inp = $input, $group = array_fill(1, $compartments, []); $val = array_pop($inp);) {
            $try = [];
            do {
                $g = rand(1, $compartments);
                $try[$g] = 0;
                $cs = array_sum($group[$g]);
                if ($cs > $perGroup) {
                    continue 3;
                }
            } while ($cs >= $perGroup - $val && count($try) < $compartments);
            $group[$g][] = $val;
        }
        foreach ($group as $grp) {
            if (array_sum($grp) != $perGroup) {
                continue 2;
            }
        }
        if ($minFg == 0 || count($group[1]) <= $minFg) {
            $i++;
            $minFg = count($group[1]);
            $qe = array_product($group[1]);
            if ($minQe == 0 || $qe < $minQe) {
                $minQe = $qe;
            }
        }
    }
    return $minQe;
}
开发者ID:earncef,项目名称:AdventOfCode,代码行数:31,代码来源:sol.php

示例5: _runAll

 private function _runAll()
 {
     $config = $this->manager;
     $idle = (bool) array_product($config->getLocks());
     if (!$idle) {
         $this->watchDog();
         return true;
     }
     // not using array_map() because error wont be thrown
     for ($jid = 0; $jid < count($this->jobs); $jid++) {
         $job = $this->jobs[$jid];
         $jname = $this->manager->getJobName($jid);
         if (!$job->coolingDown()) {
             $job->lock();
             $time = time();
             $job->run();
             $time = time() - $time;
             $job->unlock();
             $this->logInfo("<Job Runned> job-name: {$jname}, time-elapsed: {$time}");
         } else {
             $this->logInfo("<Job Blocked> job-name: {$jname}");
         }
     }
     return true;
 }
开发者ID:hchsiao,项目名称:php-virtual-process,代码行数:25,代码来源:Process.php

示例6: product

 public function product()
 {
     if (!isset($this->computed['product'])) {
         $this->computed['product'] = array_product($this->data);
     }
     return $this->computed['product'];
 }
开发者ID:pwwang,项目名称:math.php,代码行数:7,代码来源:Stats.php

示例7: operacion

 private static function operacion($tipo, $liga, $col, $cond = false)
 {
     if ($liga->existe($col)) {
         if ($cond && is_string($cond) && strpos($cond, '#[') !== false) {
             $cond = str_replace('#[', '@[', $cond);
             $num = 0;
             $con = 0;
             $pasa = 0;
             while ($liga->filas()) {
                 if ($liga->cond(++$con, $cond) && ($dato = strval($liga->dato($con, $col)))) {
                     if ($tipo == 'prod') {
                         $num ? $num *= $dato : ($num = $dato * 1);
                     } else {
                         $num += $dato;
                     }
                     $pasa++;
                 }
             }
             return $tipo == 'prom' ? $num / $pasa : $num;
         }
         $col = $liga->columna($col);
         if ($tipo == 'sum') {
             return array_sum($col);
         } elseif ($tipo == 'prod') {
             return array_product($col);
         }
         return array_sum($col) / $liga->numReg();
     }
     return "No existe la columna '{$col}'";
 }
开发者ID:oscargalileo,项目名称:liga3,代码行数:30,代码来源:Formula.php

示例8: render

 /**
  * @param mixed $a
  * @param mixed $b
  * @return mixed
  * @throw Exception
  */
 public function render($a = NULL, $b = NULL)
 {
     if ($a === NULL) {
         $a = $this->renderChildren();
     }
     if ($a === NULL) {
         throw new Exception('Required argument "a" was not supplied', 1237823699);
     }
     if ($b === NULL) {
         throw new Exception('Required argument "b" was not supplied', 1237823699);
     }
     $aIsIterable = $this->assertIsArrayOrIterator($a);
     $bIsIterable = $this->assertIsArrayOrIterator($b);
     if ($aIsIterable === TRUE) {
         if ($b === NULL) {
             return array_product($a);
         }
         $aCanBeAccessed = $this->assertSupportsArrayAccess($a);
         $bCanBeAccessed = $this->assertSupportsArrayAccess($b);
         if ($aCanBeAccessed === FALSE || $bCanBeAccessed === FALSE) {
             throw new Exception('Math operation attempted on an inaccessible Iterator. Please implement ArrayAccess or convert the value to an array before calculation', 1351891091);
         }
         foreach ($a as $index => $value) {
             $a[$index] = $value * ($bIsIterable === TRUE ? $b[$index] : $b);
         }
         return $a;
     } elseif ($bIsIterable === TRUE) {
         // condition matched if $a is not iterable but $b is.
         throw new Exception('Math operation attempted using an iterator $b against a numeric value $a. Either both $a and $b, or only $a, must be array/Iterator', 1351890876);
     }
     return $a * $b;
 }
开发者ID:nyxos,项目名称:vhs,代码行数:38,代码来源:ProductViewHelper.php

示例9: classify

 /**
  * Classifies a document string and returns the top N predicted classes and their scores.
  *
  * @param string    $document   The document to classify
  * @param int       $top        Number of top classes to return.
  *
  * @return array    A descendingly sorted list of classes and their scores. Example: array("class" => "score", ...)
  */
 public function classify($document, $top = 5)
 {
     $words = $this->normalize(explode(" ", $document));
     $classes = $this->store->getAllClasses();
     //prior probabilities
     $priors = array();
     $totalDocuments = $this->store->getDocumentCount();
     foreach ($classes as $class) {
         $priors[$class] = $this->store->getClassCount($class) / $totalDocuments;
     }
     //vocabulary
     $vocabulary = $this->store->countVocabulary();
     //conditional probabilities
     $conditionals = array();
     foreach ($classes as $class) {
         foreach ($words as $word) {
             $countWordInClass = $this->store->countWordInClass($word, $class);
             $wordsInClass = $this->store->countWordsInClass($class);
             $conditionals[$class][$word] = ($countWordInClass + 1) / ($wordsInClass + $vocabulary + 1);
         }
     }
     //probabilities
     $probabilities = array();
     foreach ($classes as $class) {
         $probabilities[$class] = $priors[$class] * array_product($conditionals[$class]);
     }
     //sort
     arsort($probabilities);
     return array_slice($probabilities, 0, $top);
 }
开发者ID:mcheptea,项目名称:nbclassifier,代码行数:38,代码来源:Classifier.php

示例10: execute

 /**
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output);
     if ($this->initMagento()) {
         if (\Mage::helper('core')->isModuleEnabled('Nexcessnet_Turpentine')) {
             $admin = \Mage::getModel('turpentine/varnish_admin');
             $cfgr = $admin->getConfigurator();
             if (!$cfgr) {
                 throw new \RuntimeException('Could not connect to Varnish admin port. Please check settings (port, secret key).');
             }
             $result = $cfgr->save($cfgr->generate());
             # (success, optional_error)
             if (!$result[0]) {
                 throw new \RuntimeException('Could not save VCL to disk: ' . $result[1]);
             }
             $result = $admin->applyConfig();
             if (!(bool) array_product($result)) {
                 throw new \RuntimeException('Could not apply VCL to all running Varnish instances');
             } else {
                 $output->writeln('<info>The Varnish VCL has successfully been generated and loaded.</info>');
             }
         } else {
             $output->writeln('<error>Turpentine is not enabled or installed.</error>');
         }
     }
 }
开发者ID:Hypernode,项目名称:hypernode-magerun,代码行数:31,代码来源:ConfigSaveCommand.php

示例11: _get_total_score

 /**
  * Get the total score using the passed amount of ingredients.
  *
  * @param array $ingredient_counts Array of ingredients and their amount of spoons.
  * @return integer The total cookie score.
  */
 private function _get_total_score($ingredient_counts)
 {
     $total_score_raw = $this->_get_total_score_raw($ingredient_counts);
     // Ignore the calories for the score.
     unset($total_score_raw['calories']);
     return array_product($total_score_raw);
 }
开发者ID:noplanman,项目名称:advent,代码行数:13,代码来源:15.php

示例12: calcSmallest

function calcSmallest($packets, $weight)
{
    $checkStr = implode(array_fill(0, count($packets), 1));
    $checkDec = bindec($checkStr);
    for ($i = 0; $i <= $checkDec; $i++) {
        $binStr = decbin($i);
        if (isset($smallest) && substr_count($binStr, "1") > $smallest[0]) {
            continue;
        }
        $binStrArr = str_split(str_pad($binStr, count($packets), "0", STR_PAD_LEFT));
        $new_vals = [];
        foreach ($binStrArr as $key => $value) {
            $new_vals[] = $value * $packets[$key];
        }
        $new_vals = array_filter($new_vals);
        if (array_sum($new_vals) == $weight) {
            $newLen = count($new_vals);
            $newQuan = array_product($new_vals);
            if (isset($smallest)) {
                if ($newLen <= $smallest[0] && $newQuan < $smallest[1]) {
                    $smallest = [$newLen, $newQuan];
                }
            } else {
                $smallest = [$newLen, $newQuan];
            }
        }
    }
    return $smallest[1];
}
开发者ID:blueprint1985,项目名称:AdventOfCode,代码行数:29,代码来源:day24_1.php

示例13: getAreaQuantumEntanglement

 /**
  * Get the product of all the gifts in a given area.
  *
  * @param string $area
  *
  * @return number
  */
 public function getAreaQuantumEntanglement($area = "passenger")
 {
     if (array_key_exists($area, $this->sleighArea)) {
         return array_product($this->sleighArea[$area]);
     }
     return false;
 }
开发者ID:jonwurtzler,项目名称:advent_of_code,代码行数:14,代码来源:SleighLayout.php

示例14: valueOf

function valueOf(array $portions)
{
    global $ingredients;
    if (count($portions) != count($ingredients)) {
        throw new Exception('count mismatch');
    }
    if (array_sum($portions) !== 100) {
        throw new Exception('Not 100');
    }
    $take = ['capacity', 'durability', 'flavor', 'texture'];
    $values = [];
    $calories = 0;
    foreach ($portions as $id => $portion) {
        foreach ($take as $ing) {
            $values[$ing] += $ingredients[$id][$ing] * $portion;
        }
        $calories += $ingredients[$id]['calories'] * $portion;
    }
    if (PART_B && $calories !== 500) {
        return 0;
    }
    //if any is negative the product is 0;
    foreach ($values as $val) {
        if ($val < 0) {
            return 0;
        }
    }
    return array_product($values);
}
开发者ID:MaMa,项目名称:adventofcode,代码行数:29,代码来源:day15.php

示例15: presscore_less_get_accent_colors

 /**
  * Helper that returns array of accent less vars.
  *
  * @since 3.0.0
  * 
  * @param  Presscore_Lib_LessVars_Manager $less_vars
  * @return array Returns array like array( 'first-color', 'seconf-color' )
  */
 function presscore_less_get_accent_colors(Presscore_Lib_LessVars_Manager $less_vars)
 {
     // less vars
     $_color_vars = array('accent-bg-color', 'accent-bg-color-2');
     // options ids
     $_test_id = 'general-accent_color_mode';
     $_color_id = 'general-accent_bg_color';
     $_gradient_id = 'general-accent_bg_color_gradient';
     // options defaults
     $_color_def = '#D73B37';
     $_gradient_def = array('#ffffff', '#000000');
     $accent_colors = $less_vars->get_var($_color_vars);
     if (!array_product($accent_colors)) {
         switch (of_get_option($_test_id)) {
             case 'gradient':
                 $colors = of_get_option($_gradient_id, $_gradient_def);
                 break;
             case 'color':
             default:
                 $colors = array(of_get_option($_color_id, $_color_def), null);
         }
         $less_vars->add_hex_color($_color_vars, $colors);
         $accent_colors = $less_vars->get_var($_color_vars);
     }
     return $accent_colors;
 }
开发者ID:10asfar,项目名称:WordPress-the7-theme-demo-,代码行数:34,代码来源:less-functions.php


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