本文整理汇总了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);
}
示例2: factorial
function factorial($num)
{
if ($num == 0) {
return 1;
}
return array_product(range(1, $num));
}
示例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);
}
示例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;
}
示例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;
}
示例6: product
public function product()
{
if (!isset($this->computed['product'])) {
$this->computed['product'] = array_product($this->data);
}
return $this->computed['product'];
}
示例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}'";
}
示例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;
}
示例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);
}
示例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>');
}
}
}
示例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);
}
示例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];
}
示例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;
}
示例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);
}
示例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;
}