本文整理汇总了PHP中abs函数的典型用法代码示例。如果您正苦于以下问题:PHP abs函数的具体用法?PHP abs怎么用?PHP abs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了abs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPoint
/**
* @brief Get the points
*/
function getPoint($member_srl, $from_db = false)
{
$member_srl = abs($member_srl);
// Get from instance memory
if (!$from_db && $this->pointList[$member_srl]) {
return $this->pointList[$member_srl];
}
// Get from file cache
$path = sprintf(_XE_PATH_ . 'files/member_extra_info/point/%s', getNumberingPath($member_srl));
$cache_filename = sprintf('%s%d.cache.txt', $path, $member_srl);
if (!$from_db && file_exists($cache_filename)) {
return $this->pointList[$member_srl] = trim(FileHandler::readFile($cache_filename));
}
// Get from the DB
$args = new stdClass();
$args->member_srl = $member_srl;
$output = executeQuery('point.getPoint', $args);
if (isset($output->data->member_srl)) {
$point = (int) $output->data->point;
$this->pointList[$member_srl] = $point;
if (!is_dir($path)) {
FileHandler::makeDir($path);
}
FileHandler::writeFile($cache_filename, $point);
return $point;
}
return 0;
}
示例2: 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})";
}
示例3: index_post
public function index_post()
{
if (IS_POST || isset($_GET['dosubmit'])) {
//print_r($_REQUEST);exit();
if (isset($_GET['type']) && $_GET['type'] == 'url') {
$sizelimit = isset($_GET['sizelimit']) && abs(intval($_GET['sizelimit'])) ? abs(intval($_GET['sizelimit'])) : $this->error('请输入每个分卷文件大小');
$this->backup_name = isset($_GET['backup_name']) && trim($_GET['backup_name']) ? trim($_GET['backup_name']) : $this->error('请输入备份名称');
$vol = $this->_get_vol();
$vol++;
} else {
$sizelimit = isset($_POST['sizelimit']) && abs(intval($_POST['sizelimit'])) ? abs(intval($_POST['sizelimit'])) : $this->error('请输入每个分卷文件大小');
$this->backup_name = isset($_POST['backup_name']) && trim($_POST['backup_name']) ? trim($_POST['backup_name']) : $this->error('请输入备份名称');
$backup_tables = isset($_POST['backup_tables']) && $_POST['backup_tables'] ? $_POST['backup_tables'] : $this->error('请选择备份数据表');
if (is_dir(SITE_PATH . $this->backup_path . $this->backup_name)) {
$this->error('备份名称已经存在');
}
mkdir(SITE_PATH . $this->backup_path . $this->backup_name);
if (!is_file(SITE_PATH . $this->backup_path . $this->backup_name . '/tbl_queue.log')) {
//写入队列
$this->_put_tbl_queue($backup_tables);
}
$vol = 1;
}
$tables = $this->_dump_queue($vol, $sizelimit * 1024);
if ($tables === false) {
$this->error('加载队列文件错误');
}
$this->_deal_result($tables, $vol, $sizelimit);
exit;
}
}
示例4: read
/**
*get
*point,offset,status
*point:请求界点,status订单状态,offset个数,为正则取大于界点point的offset个元素,反之取小于point的offset个元素
**/
protected function read()
{
$input = $this->get;
$ret = $input && $input['point'] !== false && $input['offset'] !== false && $input['status'];
if ($ret) {
$condition['token'] = $this->token;
$condition['hid'] = $this->hid;
$condition['order_status'] = $input['status'];
$limit = abs($input['offset']);
if ($input['point'] == -1) {
$ret = $this->model->listOrders($condition, $limit, true);
} else {
$is_desc = $input['offset'] < 0;
$opration_con = $is_desc ? 'lt' : 'gt';
//lt 小于,gt 大于
$condition['id'] = array($opration_con, $input['point']);
$ret = $this->model->listOrders($condition, $limit, $is_desc);
}
}
if ($ret !== false) {
$this->success("操作成功!", $ret);
} else {
$this->error('error in read');
Log::record('error' . print_r($input) . '\\n');
}
}
示例5: Create
public static function Create($user_row, $uc = true)
{
if (function_exists('zuitu_uc_register') && $uc) {
$pp = $user_row['password'];
$em = $user_row['email'];
$un = $user_row['username'];
$ret = zuitu_uc_register($em, $un, $pp);
if (!$ret) {
return false;
}
}
$user_row['username'] = htmlspecialchars($user_row['username']);
$user_row['password'] = self::GenPassword($user_row['password']);
$user_row['create_time'] = $user_row['login_time'] = time();
$user_row['ip'] = Utility::GetRemoteIp();
$user_row['secret'] = md5(rand(1000000, 9999999) . time() . $user_row['email']);
$user_row['id'] = DB::Insert('user', $user_row);
$_rid = abs(intval(cookieget('_rid')));
if ($_rid && $user_row['id']) {
$r_user = Table::Fetch('user', $_rid);
if ($r_user) {
ZInvite::Create($r_user, $user_row);
ZCredit::Invite($r_user['id']);
}
}
if ($user_row['id'] == 1) {
Table::UpdateCache('user', $user_row['id'], array('manager' => 'Y', 'secret' => ''));
}
return $user_row['id'];
}
示例6: __construct
/**
* Constructor: Generate LU decomposition of the matrix.
* As trace the permutated matrix and eliminated matrix of each step is stored.
*
* @param matrix matrix to get lu decomposition of
* @return vector permutation
*/
public function __construct(&$matrix)
{
new Assertion($matrix instanceof Matrix, 'Given matrix not of class Matrix.');
new Assertion($matrix->isSquare(), 'Matrix is not square.');
$this->_matrix = $matrix->copy();
$this->_permutation = new Vector($this->_matrix->rows());
for ($j = 0; $j < $this->_matrix->rows(); $j++) {
$pivot = $j;
for ($i = $j + 1; $i < $this->_matrix->rows(); $i++) {
if (abs($this->_matrix->get($i, $j)) > abs($this->_matrix->get($pivot, $j))) {
$pivot = $i;
}
}
$this->_permutation->set($j, $pivot);
$this->_matrix->swapRows($j, $pivot);
// Save the matrix after permutation.
$this->_trace[$j] = array('permutation' => $this->_matrix->copy());
for ($i = $j + 1; $i < $this->_matrix->columns(); $i++) {
$this->_matrix->set($i, $j, $this->_matrix->get($i, $j) / $this->_matrix->get($j, $j));
for ($k = $j + 1; $k < $this->_matrix->columns(); $k++) {
$this->_matrix->set($i, $k, $this->_matrix->get($i, $k) - $this->_matrix->get($i, $j) * $this->_matrix->get($j, $k));
}
}
// Save the matrix after elimination.
$this->_trace[$j]['elimination'] = $this->_matrix->copy();
}
}
示例7: format
function format()
{
$base = $_REQUEST['_router_'];
if ($this->curpage > 1) {
$html[] = "<a href='{$this->router}'>首页</a>";
}
$pages = array();
for ($i = 1; $i <= $this->pagenum; $i++) {
if ($i <= 3 || abs($this->curpage - $i) < 3 || $this->pagenum - $i <= 3) {
$pages[] = $i;
continue;
}
}
$html = array();
foreach ($pages as $i => $p) {
if ($i > 1 && $p - $pages[$i - 1] > 1) {
$html[] = '...';
} else {
$this->query['page'] = $p;
$url = $this->router;
$url .= strpos($url, '?') ? '&' : '?';
$url .= http_build_query($this->query);
//echo $url;
$html[] = "<a href='{$url}'>{$p}</a>";
}
}
return "共{$this->records}记录,第{$this->curpage}/{$this->pagenum}页 " . implode('', $html);
}
示例8: action_add
function action_add($input)
{
$trackerId = $input->trackerId->int();
$definition = Tracker_Definition::get($trackerId);
if (!$definition) {
throw new Services_Exception_NotFound();
}
$delayAfter = abs($input->after->int() * $input->after_unit->int());
$delayNotif = abs($input->notif->int() * $input->notif_unit->int());
$from = $input->from->word();
$to = $input->to->word();
$event = $input->event->word();
$subject = $input->subject->text();
$body = $input->body->text();
$todolib = TikiLib::lib('todo');
if (!$delayAfter) {
throw new Services_Exception_MissingValue('after');
}
$todoId = $todolib->addTodo($delayAfter, $event, 'tracker', $trackerId, array('status' => $from), array('status' => $to));
if ($delayNotif) {
$detail = array('mail' => 'creator', 'before' => $delayNotif);
if ($subject) {
$detail['subject'] = $subject;
}
if ($body) {
$detail['body'] = $body;
}
$todolib->addTodo($delayAfter - $delayNotif, $event, 'todo', $todoId, "", $detail);
}
return array('trackerId' => $trackerId, 'todoId' => $todoId);
}
示例9: getSize
function getSize($TextString, $Format = "")
{
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
$ShowLegend = isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
$LegendOffset = isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
$DrawArea = isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
$FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : 12;
$Height = isset($Format["Height"]) ? $Format["Height"] : 30;
$TextString = $this->encode39($TextString);
$BarcodeLength = strlen($this->Result);
if ($DrawArea) {
$WOffset = 20;
} else {
$WOffset = 0;
}
if ($ShowLegend) {
$HOffset = $FontSize + $LegendOffset + $WOffset;
} else {
$HOffset = 0;
}
$X1 = cos($Angle * PI / 180) * ($WOffset + $BarcodeLength);
$Y1 = sin($Angle * PI / 180) * ($WOffset + $BarcodeLength);
$X2 = $X1 + cos(($Angle + 90) * PI / 180) * ($HOffset + $Height);
$Y2 = $Y1 + sin(($Angle + 90) * PI / 180) * ($HOffset + $Height);
$AreaWidth = max(abs($X1), abs($X2));
$AreaHeight = max(abs($Y1), abs($Y2));
return array("Width" => $AreaWidth, "Height" => $AreaHeight);
}
示例10: testGetRequestOrderPayment
/**
* Test case for oePayPalIPNRequestPaymentSetter::getRequestOrderPayment
* Test case for oePayPalIPNRequestPaymentSetter::setRequestOrderPayment
* Test case for oePayPalIPNRequestPaymentSetter::_prepareOrderPayment
* Test case for oePayPalIPNRequestPaymentSetter::getRequest
* Test case for oePayPalIPNRequestPaymentSetter::getAction
* Test case for oePayPalIPNRequestPaymentSetter::getAmount
*
* @param array $aParams parameters for POST imitating PayPal.
* @param string $expectedAction Expected action for resulting payment.
*
* @dataProvider providerGetRequestOrderPayment
*/
public function testGetRequestOrderPayment($aParams, $expectedAction)
{
$oPayPalExpectedPayment = new oePayPalOrderPayment();
if (!empty($aParams)) {
$oPayPalExpectedPayment->setStatus($aParams['payment_status']);
$oPayPalExpectedPayment->setTransactionId($aParams['txn_id']);
$oPayPalExpectedPayment->setCurrency($aParams['mc_currency']);
$oPayPalExpectedPayment->setAmount(abs($aParams['mc_gross']));
$oPayPalExpectedPayment->setAction($expectedAction);
$correlationId = empty($aParams['correlation_id']) ? $aParams['ipn_track_id'] : $aParams['correlation_id'];
$oPayPalExpectedPayment->setCorrelationId($correlationId);
$oPayPalExpectedPayment->setDate(date('Y-m-d H:i:s', strtotime($aParams['payment_date'])));
} else {
$oPayPalExpectedPayment->setStatus(null);
$oPayPalExpectedPayment->setTransactionId(null);
$oPayPalExpectedPayment->setCurrency(null);
$oPayPalExpectedPayment->setAmount(null);
$oPayPalExpectedPayment->setCorrelationId(null);
$oPayPalExpectedPayment->setDate(null);
$oPayPalExpectedPayment->setAction('capture');
}
$_POST = $aParams;
$oRequest = new oePayPalRequest();
$oPayPalPayment = new oePayPalOrderPayment();
$oPayPalIPNRequestSetter = new oePayPalIPNRequestPaymentSetter();
$oPayPalIPNRequestSetter->setRequest($oRequest);
$oPayPalIPNRequestSetter->setRequestOrderPayment($oPayPalPayment);
$oRequestOrderPayment = $oPayPalIPNRequestSetter->getRequestOrderPayment();
$this->assertEquals($oPayPalExpectedPayment, $oRequestOrderPayment, 'Payment object do not have request parameters.');
}
示例11: customTimeMetric
/**
* @param string $name
* @param int $second
* @param int $first
*/
public function customTimeMetric($name, &$second, &$first)
{
if (empty($second) || empty($first)) {
return;
}
$this->customMetric($name, round(abs($second - $first) * 1000, 0));
}
示例12: sum
/**
* @param mixed:\DateInterval|\DateInterval[] $vars
* @param \DateInterval $vars,...
* @return \DateInterval
*/
public static function sum()
{
$intervals = array();
foreach (func_get_args() as $e) {
if (is_array($e)) {
$intervals = array_merge($intervals, array_values($e));
} else {
$intervals[] = $e;
}
}
$base = $intervals[0];
unset($intervals[0]);
try {
/* @var $intervals \DateInterval[] */
$intervals = ParameterConverter::toArray($intervals, '\\DateInterval');
} catch (\DomainException $e) {
throw new \InvalidArgumentException('This method only accepts \\DateInterval objects.');
}
$s = self::toSeconds($base);
foreach ($intervals as $interval) {
/* @var $interval \DateInterval */
if (!$interval->invert) {
$s += self::toSeconds($interval);
} else {
$s -= self::toSeconds($interval);
}
}
$result = new \DateInterval(sprintf('PT%dS', abs($s)));
$result = new \DateInterval(self::shortenString($result));
if ($s < 0) {
$result->invert = true;
}
return $result;
}
示例13: get_suggestions
/**
*
* Returns array of people containing entity, mutuals (friends), groups (shared) and priority
* @param Int $guid
* @param Int $friends_limit
* @param Int $groups_limit
* @return Array
*/
function get_suggestions($guid, $friends_of_friends_limit = 10, $groups_members_limit = 10)
{
$dbprefix = elgg_get_config('dbprefix');
$guid = sanitize_int($guid);
$suggestions = array();
if ($friends_of_friends_limit) {
// get some friends of friends
$options = array('selects' => array('COUNT(fof.guid_two) as priority'), 'type' => 'user', 'joins' => array("JOIN {$dbprefix}users_entity ue ON ue.guid = e.guid", "JOIN {$dbprefix}entity_relationships fr ON fr.guid_one = {$guid} AND fr.relationship = 'friend'", "JOIN {$dbprefix}entity_relationships fof ON fof.guid_one = fr.guid_two AND fof.relationship = 'friend'"), "wheres" => array("ue.banned = 'no'", "e.guid NOT IN (SELECT f.guid_two FROM {$dbprefix}entity_relationships f WHERE f.guid_one = {$guid} AND f.relationship = 'friend')", "fof.guid_two = e.guid", "e.guid != {$guid}"), 'group_by' => 'e.guid', 'order_by' => 'priority desc, ue.last_action desc', 'limit' => abs((int) $friends_of_friends_limit));
$fof = elgg_get_entities($options);
foreach ($fof as $f) {
$priority = (int) $f->getVolatileData('select:priority');
$suggestions[$f->guid] = array('entity' => $f, 'mutuals' => $priority, 'groups' => 0, 'priority' => $priority);
}
}
if ($groups_members_limit) {
// get some mutual group members
$options = array('selects' => array('COUNT(mog.guid_two) as priority'), 'type' => 'user', 'joins' => array("JOIN {$dbprefix}users_entity ue ON ue.guid = e.guid", "JOIN {$dbprefix}entity_relationships g ON g.guid_one = {$guid} AND g.relationship = 'member'", "JOIN {$dbprefix}groups_entity ge ON ge.guid = g.guid_two", "JOIN {$dbprefix}entity_relationships mog ON mog.guid_two = g.guid_two AND mog.relationship = 'member'"), "wheres" => array("ue.banned = 'no'", "e.guid NOT IN (SELECT f.guid_two FROM {$dbprefix}entity_relationships f WHERE f.guid_one = {$guid} AND f.relationship = 'friend')", "mog.guid_one = e.guid", "e.guid != {$guid}"), 'group_by' => 'e.guid', 'order_by' => 'priority desc, ue.last_action desc', 'limit' => 3);
// get members of groups
$mog = elgg_get_entities($options);
foreach ($mog as $m) {
if (!isset($suggestions[$m->guid])) {
$priority = (int) $m->getVolatileData('select:priority');
$suggestions[$m->guid] = array('entity' => $m, 'mutuals' => 0, 'groups' => $priority, 'priority' => $priority);
} else {
$priority = (int) $m->getVolatileData('select:priority');
$suggestions[$m->guid]['groups'] = $priority;
$suggestions[$m->guid]['priority'] += $priority;
}
}
}
// sort by priority
usort($suggestions, __NAMESPACE__ . '\\suggested_friends_sorter');
return $suggestions;
}
示例14: _toHtml
/**
* Render customer orders list xml
*
* @return string
*/
protected function _toHtml()
{
/** @var $ordersXmlObj Mage_XmlConnect_Model_Simplexml_Element */
$ordersXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<orders></orders>');
/** @var $orders Mage_Sales_Model_Resource_Order_Collection */
$orders = Mage::getResourceModel('sales/order_collection')->addFieldToSelect('*')->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))->setOrder('created_at', 'desc');
/** @var $request Mage_Core_Controller_Request_Http */
$request = $this->getRequest();
/**
* Apply offset and count
*/
$count = abs((int) $request->getParam('count', 0));
$count = $count ? $count : self::ORDERS_LIST_LIMIT;
$offset = abs((int) $request->getParam('offset', 0));
$ordersXmlObj->addAttribute('orders_count', $ordersXmlObj->escapeXml($orders->count()));
$ordersXmlObj->addAttribute('offset', $ordersXmlObj->escapeXml($offset));
$orders->clear()->getSelect()->limit($count, $offset);
$orders->load();
if ($orders->count()) {
foreach ($orders as $order) {
$item = $ordersXmlObj->addChild('item');
$item->addChild('entity_id', $order->getId());
$item->addChild('number', $order->getRealOrderId());
$item->addChild('date', $this->formatDate($order->getCreatedAtStoreDate()));
if ($order->getShippingAddress()) {
$item->addChild('ship_to', $ordersXmlObj->escapeXml($order->getShippingAddress()->getName()));
}
$item->addChild('total', $order->getOrderCurrency()->formatPrecision($order->getGrandTotal(), 2, array(), false, false));
$item->addChild('status', $order->getStatusLabel());
}
}
return $ordersXmlObj->asNiceXml();
}
示例15: cdn_img_url
/**
* CDN图片域名
*
* @param string $img 图片地址
* @param string $path 附加路径
* @return string 完整URL图片地址
*/
function cdn_img_url($img, $path = '/')
{
if (empty($img) || strpos($img, '://') !== false) {
return $img;
}
if ($img[0] == '/') {
$path = '';
}
/**
* 当使用本机时,就不用CDN处理了
*/
if (isset($_GET['local'])) {
return "{$path}{$img}";
}
if (USE_ISLOCAL_JS2CSS || USE_ISLOCAL_IMG) {
$file_ext = strtolower(strrchr($img, '.'));
if (USE_ISLOCAL_JS2CSS && ($file_ext == '.js' || $file_ext == '.css')) {
return "{$path}{$img}";
}
if (USE_ISLOCAL_IMG && ($file_ext == '.jpg' || $file_ext == '.jpeg' || $file_ext == '.gif' || $file_ext == '.swf' || $file_ext == '.png')) {
return "{$path}{$img}";
}
}
/**
* 分服务器加载
*/
static $img_hosts = null;
static $img_count = null;
if (is_null($img_hosts)) {
$img_hosts = json_decode(IMG_URLS, true);
$img_count = count($img_hosts);
}
$key = abs(crc32($img)) % $img_count;
return "{$img_hosts[$key]}{$path}{$img}";
}