本文整理汇总了PHP中array_sum函数的典型用法代码示例。如果您正苦于以下问题:PHP array_sum函数的具体用法?PHP array_sum怎么用?PHP array_sum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_sum函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format
public function format(Node $node, Document $document)
{
$node->convertRelativeWidthsOfColumns();
$node->reduceColumnsWidthsByMargins();
$columnsWidths = $node->getWidthsOfColumns();
$columnsMarginsLeft = $node->getMarginsLeftOfColumns();
$columnsMarginsRight = $node->getMarginsRightOfColumns();
$numberOfColumns = $node->getNumberOfColumns();
$totalColumnsWidth = array_sum($columnsWidths);
$tableWidth = $node->getWidth();
$enlargeColumnWidth = $numberOfColumns ? ($tableWidth - $totalColumnsWidth) / count($columnsWidths) : 0;
foreach ($columnsWidths as $index => $width) {
$columnsWidths[$index] += $enlargeColumnWidth;
}
foreach ($node->getChildren() as $row) {
foreach ($row->getChildren() as $cell) {
$column = $cell->getNumberOfColumn();
$colspan = $cell->getColspan();
$newWidth = 0;
for ($i = 0; $i < $colspan; $i++) {
$newWidth += $columnsWidths[$column + $i];
}
$horizontalPaddings = $cell->getPaddingLeft() + $cell->getPaddingRight();
$cell->setWidth($newWidth - $horizontalPaddings);
$cell->setMarginLeft($columnsMarginsLeft[$column]);
$cell->setMarginRight($columnsMarginsRight[$column + $colspan - 1]);
}
}
}
示例2: __construct
public function __construct(array $outputs, $confirms = 1)
{
$this->data = $outputs;
$this->minimumConfirms = $confirms;
$this->total = count($outputs);
// do calculation only if at least 1 output
if ($this->total > 0) {
$amounts = array_column($outputs, 'amount');
$this->amountsSum = array_sum($amounts);
$amountPairs = [];
foreach ($amounts as $amount) {
$amount = (string) $amount;
// cast float to string, because array_key_exists can handle only string or integer
// if key exists, then add +1 to value that means that amount already was counted
if (array_key_exists($amount, $amountPairs)) {
$amountPairs[$amount] = $amountPairs[$amount] + 1;
} else {
// new result, just add initial 1
$amountPairs[$amount] = 1;
}
}
$this->amountPairs = $amountPairs;
ksort($this->amountPairs);
// sort incrementing by amount
}
}
示例3: chmodnum
function chmodnum($chmod)
{
$trans = array('-' => '0', 'r' => '4', 'w' => '2', 'x' => '1');
$chmod = substr(strtr($chmod, $trans), 1);
$array = str_split($chmod, 3);
return array_sum(str_split($array[0])) . array_sum(str_split($array[1])) . array_sum(str_split($array[2]));
}
示例4: FancyTable
function FancyTable($header, $data)
{
// Couleurs, épaisseur du trait et police grasse
$this->SetFillColor(255, 0, 0);
$this->SetTextColor(255);
$this->SetDrawColor(128, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
// En-tête
$w = array(40, 35, 45, 40);
for ($i = 0; $i < count($header); $i++) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', true);
}
$this->Ln();
// Restauration des couleurs et de la police
$this->SetFillColor(224, 235, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Données
$fill = false;
foreach ($data as $row) {
$this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
$this->Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
$this->Cell($w[2], 6, number_format($row[2], 0, ',', ' '), 'LR', 0, 'R', $fill);
$this->Cell($w[3], 6, number_format($row[3], 0, ',', ' '), 'LR', 0, 'R', $fill);
$this->Ln();
$fill = !$fill;
}
// Trait de terminaison
$this->Cell(array_sum($w), 0, '', 'T');
}
示例5: callback
function callback($path = '', $blog_id = 0)
{
$blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
if (is_wp_error($blog_id)) {
return $blog_id;
}
//upload_files can probably be used for other endpoints but we want contributors to be able to use media too
if (!current_user_can('edit_posts')) {
return new WP_Error('unauthorized', 'User cannot view media', 403);
}
$args = $this->query_args();
if ($args['number'] < 1) {
$args['number'] = 20;
} elseif (100 < $args['number']) {
return new WP_Error('invalid_number', 'The NUMBER parameter must be less than or equal to 100.', 400);
}
$media = get_posts(array('post_type' => 'attachment', 'post_parent' => $args['parent_id'], 'offset' => $args['offset'], 'numberposts' => $args['number'], 'post_mime_type' => $args['mime_type']));
$response = array();
foreach ($media as $item) {
$response[] = $this->get_media_item($item->ID);
}
$_num = (array) wp_count_attachments();
$_total_media = array_sum($_num) - $_num['trash'];
$return = array('found' => $_total_media, 'media' => $response);
return $return;
}
示例6: lotteryWeighted
/**
* @param array $words 抽出対象の配列($weightsと要素数は同数)
* @param array $weights 重みの配列(要素はint型)
*
* @return mixed $word 抽出された要素
*
* @throws Exception Validationエラー時に投げられる例外
*/
function lotteryWeighted($words, $weights)
{
//Validation.
try {
foreach ($weights as $weight) {
if (!is_int($weight)) {
throw new Exception("Weights only type int.");
}
}
$targets = array_combine($words, $weights);
if (!$targets) {
throw new Exception("The number of elements does not match.");
}
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
//抽出
$sum = array_sum($targets);
$judgeVal = rand(1, $sum);
foreach ($targets as $word => $weight) {
if (($sum -= $weight) < $judgeVal) {
return $word;
}
}
}
示例7: browse
/**
* Browse all absence types
*
*
* @return void
* @access public
* @static
*/
function browse()
{
// get all appraisal criteria sorted by value
$appraisalCriteria = array();
$dao = new CRM_Appraisals_DAO_AppraisalCriteria();
$dao->orderBy('value');
$dao->find();
$count = $dao->count();
$i = 1;
while ($dao->fetch()) {
$appraisalCriteria[$dao->id] = array();
$appraisalCriteria[$dao->id]['id'] = $dao->id;
$appraisalCriteria[$dao->id]['value'] = $dao->value;
$appraisalCriteria[$dao->id]['label'] = $dao->label;
$appraisalCriteria[$dao->id]['is_active'] = $dao->is_active;
// form all action links
$action = array_sum(array_keys($this->links()));
if ($dao->is_active) {
$action -= CRM_Core_Action::ENABLE;
} else {
$action -= CRM_Core_Action::DISABLE;
}
$canBeDeleted = TRUE;
if ($i !== $count) {
$canBeDeleted = FALSE;
}
if (!$canBeDeleted) {
$action -= CRM_Core_Action::DELETE;
}
$appraisalCriteria[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id));
$i++;
}
$this->assign('rows', $appraisalCriteria);
}
示例8: query_report_data
/**
* Get all data needed for this report and store in the class
*/
private function query_report_data()
{
$this->report_data = new stdClass();
$this->report_data->orders = (array) $this->get_order_report_data(array('data' => array('_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_sales'), '_order_shipping' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_shipping'), '_order_tax' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_tax'), '_order_shipping_tax' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_shipping_tax'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => array_merge(array('shop_order_refund'), wc_get_order_types('sales-reports')), 'order_status' => array('completed', 'processing', 'on-hold'), 'parent_order_status' => array('completed', 'processing', 'on-hold')));
$this->report_data->order_counts = (array) $this->get_order_report_data(array('data' => array('ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'count', 'distinct' => true), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold')));
$this->report_data->coupons = (array) $this->get_order_report_data(array('data' => array('order_item_name' => array('type' => 'order_item', 'function' => '', 'name' => 'order_item_name'), 'discount_amount' => array('type' => 'order_item_meta', 'order_item_type' => 'coupon', 'function' => 'SUM', 'name' => 'discount_amount'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'where' => array(array('key' => 'order_items.order_item_type', 'value' => 'coupon', 'operator' => '=')), 'group_by' => $this->group_by_query . ', order_item_name', 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold')));
$this->report_data->order_items = (array) $this->get_order_report_data(array('data' => array('_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_count'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'where' => array(array('key' => 'order_items.order_item_type', 'value' => 'line_item', 'operator' => '=')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('completed', 'processing', 'on-hold')));
$this->report_data->refunded_order_items = (array) $this->get_order_report_data(array('data' => array('_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_count'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'where' => array(array('key' => 'order_items.order_item_type', 'value' => 'line_item', 'operator' => '=')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('refunded')));
$this->report_data->partial_refunds = (array) $this->get_order_report_data(array('data' => array('_refund_amount' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_refund'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date'), '_qty' => array('type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => 'SUM', 'name' => 'order_item_count')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_status' => false, 'parent_order_status' => array('completed', 'processing', 'on-hold')));
foreach ($this->report_data->partial_refunds as $key => $value) {
$this->report_data->partial_refunds[$key]->order_item_count = $this->report_data->partial_refunds[$key]->order_item_count * -1;
}
$this->report_data->order_items = array_merge($this->report_data->order_items, $this->report_data->partial_refunds);
$this->report_data->total_order_refunds = array_sum((array) absint($this->get_order_report_data(array('data' => array('ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders')), 'query_type' => 'get_var', 'filter_range' => true, 'order_types' => wc_get_order_types('order-count'), 'order_status' => array('refunded')))));
$this->report_data->full_refunds = (array) $this->get_order_report_data(array('data' => array('_order_total' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_refund'), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true, 'order_status' => array('refunded')));
$this->report_data->refunds = array_merge($this->report_data->partial_refunds, $this->report_data->full_refunds);
$this->report_data->total_sales = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_sales')), 2);
$this->report_data->total_tax = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_tax')), 2);
$this->report_data->total_shipping = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_shipping')), 2);
$this->report_data->total_shipping_tax = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->orders, 'total_shipping_tax')), 2);
$this->report_data->total_refunds = wc_format_decimal(array_sum(wp_list_pluck($this->report_data->partial_refunds, 'total_refund')) + array_sum(wp_list_pluck($this->report_data->full_refunds, 'total_refund')), 2);
$this->report_data->total_coupons = number_format(array_sum(wp_list_pluck($this->report_data->coupons, 'discount_amount')), 2);
$this->report_data->total_orders = absint(array_sum(wp_list_pluck($this->report_data->order_counts, 'count')));
$this->report_data->total_partial_refunds = array_sum(wp_list_pluck($this->report_data->partial_refunds, 'order_item_count')) * -1;
$this->report_data->total_item_refunds = array_sum(wp_list_pluck($this->report_data->refunded_order_items, 'order_item_count')) * -1;
$this->report_data->total_items = absint(array_sum(wp_list_pluck($this->report_data->order_items, 'order_item_count')) * -1);
$this->report_data->average_sales = wc_format_decimal($this->report_data->total_sales / ($this->chart_interval + 1), 2);
$this->report_data->net_sales = wc_format_decimal($this->report_data->total_sales - $this->report_data->total_shipping - $this->report_data->total_tax - $this->report_data->total_shipping_tax, 2);
}
示例9: esc
function esc($dbfname, $estructura, $contenido)
{
$fdbf = fopen($dbfname, 'w');
$long_estruc = count($estructura);
$primer_registro = ($long_estruc + 1) * 32 + 1;
$longitud_total = array_sum(array_map(function ($element) {
return $element['longitud'];
}, $estructura));
$bin = pack("C4Vv2@32", 3, date("y"), date("m"), date("d"), count($contenido), $primer_registro, $longitud_total + 1);
$ini = 1;
foreach ($estructura as $est) {
$bin .= pack("a11A1VC2@32", $est["nombre"], $est["tipo"], $ini, $est["longitud"], $est["decimales"]);
$ini += $est["longitud"];
}
$bin .= pack("C", 13);
foreach ($contenido as $cont) {
$bin .= pack("C", 32);
for ($i = 0; $i < $long_estruc; $i++) {
echo $i . " <br />";
$bin .= pack("A" . $estructura[$i]['longitud'], $cont[$i]);
}
}
$bin .= pack("C", 26);
// echo "<br /><br />";
print_r(unpack("C*", $bin));
fwrite($fdbf, $bin);
fclose($fdbf);
}
示例10: super_croissance_check
function super_croissance_check($tab = array())
{
$current_tab = array();
if (!count_tab($tab)) {
echo "ceci est pas un tableau\n";
return false;
} else {
// tableau de check
$tab_check = array();
$current_tab = count_tab($tab);
for ($i = 0; $i < $current_tab; $i++) {
$actual_count = $i;
// si c'est diferrent de zero
for ($j = 0; $j < $actual_count; $j++) {
// on push les valeur dans un autre tableau
array_push($tab_check, $tab[$j]);
}
// on place la somme du tableau dans une variable
$result = array_sum($tab_check);
// si le tableau n'est pas une supercroissante
if ($tab[$actual_count] < $result) {
echo "le tableau n'est pas une suite supercroissante\n";
return false;
}
// on reset le tableau pour le prochain resultat
$tab_check = array();
}
// on affiche un message si c'est bien une suite supercroissante
return true;
}
}
示例11: newPID
/**
* Generate a new PID
*/
function newPID()
{
// The PID is split into two parts. $checksum is appended to $prefix
// to make the full number.
if ($this->find('count') > 0) {
// Get the last PID, work out its prefix and increment by one
$lastPid = $this->find('first', array('fields' => array('Patient.pid'), 'order' => array('Patient.pid DESC')));
$lastPid = $lastPid['Patient']['pid'];
$prefix = substr($lastPid, 0, strlen($lastPid) - 1) + 1;
} else {
// This is the prefix to the first PID we will ever assign
$prefix = 1;
}
// Split the prefix into an array in a right-to-left fashion
$prefixArray = array_reverse(str_split($prefix));
// Starting with the first digit, double every other number
for ($i = 0; $i < count($prefixArray); $i += 2) {
$prefixArray[$i] = $prefixArray[$i] * 2;
}
// Add all of the digits up
$digits = '';
foreach ($prefixArray as $value) {
$digits .= $value;
}
$sum = array_sum(str_split($digits));
// When $checksum is added modulo ten, it should equal zero
$checksum = (10 - $sum % 10) % 10;
return $prefix . $checksum;
}
示例12: BuildTable
function BuildTable($header, $data)
{
//Colors, line width and bold font
$this->SetFillColor(255, 255, 255);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');
//Header
// make an array for the column widths
$w = array(30, 30, 50, 50, 30, 60);
// send the headers to the PDF document
for ($i = 0; $i < count($header); $i++) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();
//Color and font restoration
$this->SetFillColor(175);
$this->SetTextColor(0);
$this->SetFont('');
//now spool out the data from the $data array
$fill = true;
// used to alternate row color backgrounds
foreach ($data as $row) {
$this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
$this->Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
$this->Cell($w[2], 6, $row[2], 'LR', 0, 'L', $fill);
$this->Cell($w[3], 6, $row[3], 'LR', 0, 'L', $fill);
$this->Cell($w[4], 6, $row[4], 'LR', 0, 'L', $fill);
$this->Cell($w[5], 6, number_format($row[5]), 'LR', 0, 'R', $fill);
$this->Ln();
$fill = !$fill;
}
$this->Cell(array_sum($w), 0, '', 'T');
}
示例13: FancyTable
function FancyTable($header, $data)
{
// Colors, line width and bold font
$this->SetFillColor(255, 0, 0);
$this->SetTextColor(255);
$this->SetDrawColor(128, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', '');
// Header
$w = array(40, 35, 40, 45);
for ($i = 0; $i < count($header); $i++) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', true);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(224, 235, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = false;
foreach ($data as $row) {
$this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
// $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
// $this->Cell($w[2],6,number_format(doubleval($row[2])),'LR',0,'R',$fill);
// $this->Cell($w[3],6,number_format(doubleval($row[3])),'LR',0,'R',$fill);
$this->Ln();
$fill = !$fill;
}
// Closing line
$this->Cell(array_sum($w), 0, '', 'T');
}
示例14: getLoanSummary
public function getLoanSummary($loanid)
{
$ret = array();
$qty = array();
$this->db->select('DateReceived, Number1');
$this->db->from('loan');
$this->db->where('LoanID', $loanid);
$query = $this->db->get();
$row = $query->row();
$ret[] = $row->DateReceived . ': ' . (int) $row->Number1 . ' specimens received';
$qty[] = $row->Number1;
$this->db->select('ShipmentDate, Number1');
$this->db->from('shipment');
$this->db->where('LoanID', $loanid);
$this->db->order_by('ShipmentDate', 'asc');
$query = $this->db->get();
if ($query->num_rows()) {
foreach ($query->result() as $row) {
$ret[] = $row->ShipmentDate . ': ' . (int) $row->Number1 . ' specimens returned';
$qty[] = $row->Number1;
}
}
$qty_outstanding = array_shift($qty);
if ($qty) {
$qty_outstanding -= array_sum($qty);
}
$ret[] = date('Y-m-d') . ': ' . (int) $qty_outstanding . ' specimens outstanding';
return $ret;
}
示例15: save_daily
public function save_daily($line_id = 0)
{
$daily = I('post.daily');
if ($line_id && !empty($daily)) {
$where['line_id'] = $line_id;
M('line_daily')->where($where)->delete();
foreach ($daily as $key => $value) {
if ($key > 0) {
$data = array();
$spot = array();
$shop = array();
$diet = $value['diet'] ? $value['diet'] : array();
foreach ($value['spot']['name'] as $spot_key => $spot_value) {
$spot[$spot_key]['name'] = $value['spot']['name'][$spot_key];
$spot[$spot_key]['time'] = $value['spot']['time'][$spot_key];
}
foreach ($value['shop']['name'] as $shop_key => $shop_value) {
$shop[$shop_key]['name'] = $value['shop']['name'][$shop_key];
$shop[$shop_key]['time'] = $value['shop']['time'][$shop_key];
}
$data['line_id'] = $line_id;
$data['name'] = $value['name'];
$data['hotel'] = $value['hotel'];
$data['diet'] = array_sum($diet);
$data['spot'] = json_encode($spot);
$data['shop'] = json_encode($shop);
$data['sort'] = $key;
M('line_daily')->add($data);
}
}
}
}