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


PHP dmArray::last方法代码示例

本文整理汇总了PHP中dmArray::last方法的典型用法代码示例。如果您正苦于以下问题:PHP dmArray::last方法的具体用法?PHP dmArray::last怎么用?PHP dmArray::last使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dmArray的用法示例。


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

示例1: getLastChild

 public function getLastChild()
 {
     return dmArray::last($this->children);
 }
开发者ID:jdart,项目名称:diem,代码行数:4,代码来源:dmMenu.php

示例2: getData

 protected function getData()
 {
     if (!($data = $this->getCache('data'))) {
         $data = array('date' => array(), 'timer' => array());
         $requestLogEntries = $this->serviceContainer->getService('request_log')->getEntries(10000, array('hydrate' => false, 'keys' => array('time', 'timer', 'code', 'mem')));
         $logDelta = dmArray::get(dmArray::first($requestLogEntries), 'time') - dmArray::get(dmArray::last($requestLogEntries), 'time');
         $hours = $logDelta / 3600;
         if ($hours < 1) {
             throw new dmException('Not enough log entries');
         }
         $stepFactor = $hours / 40;
         $step = round(60 * 60 * $stepFactor);
         $stepDate = $_SERVER['REQUEST_TIME'] - $step;
         $tmpTimes = array();
         $tmpMems = array();
         $tmpErrs = 0;
         $data = array('date' => array(), 'time' => array(), 'nbReq' => array(), 'nbErr' => array(), 'mem' => array());
         if (count($requestLogEntries) < 50) {
             throw new dmException('Not enough log entries');
         }
         foreach ($requestLogEntries as $userLogEntry) {
             $date = $userLogEntry['time'];
             $timer = $userLogEntry['timer'];
             $mem = $userLogEntry['mem'];
             $err = in_array($userLogEntry['code'], array('500', '404'));
             if ($date > $stepDate) {
                 $tmpTimes[] = $timer;
                 $tmpMems[] = $mem;
                 $tmpErrs += $err;
             } else {
                 $nb = count($tmpTimes);
                 $trustableData = $nb >= 10;
                 $data['date'][] = $stepDate;
                 $data['nbReq'][] = $trustableData ? $nb / $stepFactor : '';
                 $data['nbErr'][] = $trustableData ? $tmpErrs / $stepFactor : '';
                 $data['time'][] = $trustableData ? array_sum($tmpTimes) / $nb : '';
                 $data['mem'][] = $trustableData ? array_sum($tmpMems) / $nb : '';
                 $stepDate -= $step;
                 $tmpTimes = array($timer);
                 $tmpMems = array($mem);
                 $tmpErrs = $err;
             }
         }
         $nb = count($tmpTimes);
         $trustableData = $nb >= 5;
         $data['date'][] = $stepDate;
         $data['nbReq'][] = $nb / $stepFactor;
         $data['nbErr'][] = $tmpErrs / $stepFactor;
         $data['time'][] = $trustableData ? array_sum($tmpTimes) / $nb : "";
         $data['mem'][] = $trustableData ? array_sum($tmpMems) / $nb : "";
         foreach (array_keys($data) as $key) {
             $data[$key] = array_reverse($data[$key]);
         }
         foreach ($data['mem'] as $index => $value) {
             $data['nbReq'][$index] = $data['nbReq'][$index] / 60;
             $data['nbErr'][$index] = $data['nbErr'][$index] / 60;
             if ("" != $data['mem'][$index]) {
                 $data['mem'][$index] = $value / (1024 * 1024);
             }
             if ($data['time'][$index] > 5000) {
                 $data['time'][$index] = 5000;
             }
         }
         $events = $this->serviceContainer->getService('event_log')->getEntries(1000, array('filter' => array($this, 'filterEvent'), 'hydrate' => false));
         $data['events'] = array();
         foreach ($this->eventsFilter as $eventType) {
             $data['events'][$eventType] = array();
             for ($it = 0, $itMax = count($data['date']); $it < $itMax; $it++) {
                 $data['events'][$eventType][] = 0;
             }
         }
         $time = time();
         foreach ($events as $event) {
             $eventType = $event['action'] . ' ' . $event['type'];
             $timeDelta = $time;
             $nearestTimeIndex = null;
             foreach ($data['date'] as $index => $time) {
                 $eventTimeDelta = abs($time - $event['time']);
                 if ($eventTimeDelta < $timeDelta) {
                     $nearestTimeIndex = $index;
                     $timeDelta = $eventTimeDelta;
                 }
             }
             if ($timeDelta < $data['date'][1] - $data['date'][0]) {
                 ++$data['events'][$eventType][$nearestTimeIndex];
             }
         }
         unset($events);
         $this->setCache('data', $data);
     }
     return $data;
 }
开发者ID:theolymp,项目名称:diem,代码行数:92,代码来源:dmLogChart.php

示例3: array

$t->is_deeply(dmArray::firsts(array(), 2), null, 'empty source array');
$t->is_deeply(dmArray::firsts(array('alpha'), 2), array('alpha'), 'not enough values');
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::firsts($array, 2), array('alpha', 'beta'), 'first values');
$t->diag('get');
$t->is_deeply(dmArray::get('alpha', null, 'test'), 'test', 'first parameter is not an array');
$t->is_deeply(dmArray::get(array('alpha'), 0, 'test'), 'alpha', 'key exists');
$t->is_deeply(dmArray::get(array('alpha'), 1, 'test'), 'test', 'key not exists');
$t->is_deeply(dmArray::get(array(''), 0, 'test', false), '', 'empty value without default if empty');
$t->is_deeply(dmArray::get(array(''), 0, 'test', true), 'test', 'empty value with default if empty');
$t->is_deeply(dmArray::get(array('alpha'), 0, 'test', true), 'alpha', 'key exists with default if empty');
$t->diag('last');
$t->is_deeply(dmArray::last('alpha'), 'alpha', 'first parameter is not an array');
$t->is_deeply(dmArray::last(array()), null, 'empty source array');
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::last($array), 'delta', 'last value');
$t->diag('toHtmlCssClasses');
$classes = array('class1', '', ' class2', ' ', '  class3  ');
$cleanClasses = 'class1 class2 class3';
$t->is(dmArray::toHtmlCssClasses($classes), $cleanClasses, 'clean classes : ' . $cleanClasses);
$classes = array('class1');
$cleanClasses = 'class1';
$t->is(dmArray::toHtmlCssClasses($classes), $cleanClasses, 'clean classes : ' . $cleanClasses);
$classes = array('  class1 class2 class3  ');
$cleanClasses = 'class1 class2 class3';
$t->is(dmArray::toHtmlCssClasses($classes), $cleanClasses, 'clean classes : ' . $cleanClasses);
$t->diag('unsetEmpty');
$array = array(1 => '', 2 => 'delta', 3 => '', 'alpha' => 'gamma', 'gamma' => '', 'delta' => '');
$t->is_deeply(dmArray::unsetEmpty($array, array(3, 'gamma')), array('1' => '', '2' => 'delta', 'alpha' => 'gamma', 'delta' => ''), 'check');
$t->diag('valueToKey');
$array = array('alpha', 'beta', 'gamma', 'delta');
开发者ID:theolymp,项目名称:diem,代码行数:31,代码来源:dmArrayTest.php


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