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


PHP array_splice函数代码示例

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


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

示例1: currencies

 /**
  * Currency switcher
  *
  * @access public
  * @return void|bool|string
  */
 public static function currencies($atts)
 {
     $atts = shortcode_atts(array(), $atts, 'realia_currencies');
     if (!current_theme_supports('realia-currencies')) {
         return;
     }
     $currencies = get_theme_mod('realia_currencies');
     if ($currencies == false) {
         $currencies = array(array('symbol' => '$', 'code' => 'USD', 'show_after' => false, 'money_decimals' => 2, 'money_dec_point' => '.', 'money_thousands_separator' => ','));
     } elseif (!is_array($currencies)) {
         return false;
     }
     array_splice($currencies, get_theme_mod('realia_currencies_other', 0) + 1);
     $result = '';
     if (!empty($currencies) && is_array($currencies)) {
         ksort($currencies);
         $currency_code = Realia_Currencies::get_current_currency_code();
         $result = '';
         ob_start();
         include Realia_Template_Loader::locate('misc/currencies');
         $result = ob_get_contents();
         ob_end_clean();
     }
     return $result;
 }
开发者ID:jhonrsalcedo,项目名称:sitio,代码行数:31,代码来源:class-realia-shortcodes.php

示例2: _normalizePath

   /**
    * Removes the '..' and '.' segments from the path component
    *
    * @param    string  Path component of the URL, possibly with '.' and '..' segments
    * @return   string  Path component of the URL with '.' and '..' segments removed
    * @access   private
    */
    function _normalizePath($path)
    {
        $pathAry = explode('/', $path);
        $i       = 1;

        do {
            if ('.' == $pathAry[$i]) {
                if ($i < count($pathAry) - 1) {
                    array_splice($pathAry, $i, 1);
                } else {
                    $pathAry[$i] = '';
                    $i++;
                }

            } elseif ('..' == $pathAry[$i] && $i > 1 && '..' != $pathAry[$i - 1]) {
                if ($i < count($pathAry) -1) {
                    array_splice($pathAry, $i - 1, 2);
                    $i--;
                } else {
                    array_splice($pathAry, $i - 1, 2, '');
                }

            } else {
                $i++;
            }
        } while ($i < count($pathAry));

        return implode('/', $pathAry);
    }
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:36,代码来源:Jump.php

示例3: get_per_answer_fields

 function get_per_answer_fields(&$mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption)
 {
     //     $repeated = parent::get_per_answer_fields($mform, $label, $gradeoptions, $repeatedoptions, $answersoption);
     $repeated = array();
     $repeated[] =& $mform->createElement('header', 'answerhdr', $label);
     //   if ($this->editasmultichoice == 1){
     $repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz'), array('size' => 50));
     $repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions);
     $repeated[] =& $mform->createElement('editor', 'feedback', get_string('feedback', 'quiz'), null, $this->editoroptions);
     $repeatedoptions['answer']['type'] = PARAM_RAW;
     $repeatedoptions['fraction']['default'] = 0;
     $answersoption = 'answers';
     $mform->setType('answer', PARAM_NOTAGS);
     $addrepeated = array();
     $addrepeated[] =& $mform->createElement('hidden', 'tolerance');
     $addrepeated[] =& $mform->createElement('hidden', 'tolerancetype', 1);
     $repeatedoptions['tolerance']['type'] = PARAM_NUMBER;
     $repeatedoptions['tolerance']['default'] = 0.01;
     $addrepeated[] =& $mform->createElement('select', 'correctanswerlength', get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
     $repeatedoptions['correctanswerlength']['default'] = 2;
     $answerlengthformats = array('1' => get_string('decimalformat', 'quiz'), '2' => get_string('significantfiguresformat', 'quiz'));
     $addrepeated[] =& $mform->createElement('select', 'correctanswerformat', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
     array_splice($repeated, 3, 0, $addrepeated);
     $repeated[1]->setLabel('...<strong>{={x}+..}</strong>...');
     return $repeated;
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:26,代码来源:edit_calculatedmulti_form.php

示例4: validate

 public function validate($aIP, $config, $context)
 {
     if (!$this->ip4) {
         $this->_loadRegex();
     }
     $original = $aIP;
     $hex = '[0-9a-fA-F]';
     $blk = '(?:' . $hex . '{1,4})';
     $pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))';
     // /0 - /128
     //      prefix check
     if (strpos($aIP, '/') !== false) {
         if (preg_match('#' . $pre . '$#s', $aIP, $find)) {
             $aIP = substr($aIP, 0, 0 - strlen($find[0]));
             unset($find);
         } else {
             return false;
         }
     }
     //      IPv4-compatiblity check
     if (preg_match('#(?<=:' . ')' . $this->ip4 . '$#s', $aIP, $find)) {
         $aIP = substr($aIP, 0, 0 - strlen($find[0]));
         $ip = explode('.', $find[0]);
         $ip = array_map('dechex', $ip);
         $aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3];
         unset($find, $ip);
     }
     //      compression check
     $aIP = explode('::', $aIP);
     $c = count($aIP);
     if ($c > 2) {
         return false;
     } elseif ($c == 2) {
         list($first, $second) = $aIP;
         $first = explode(':', $first);
         $second = explode(':', $second);
         if (count($first) + count($second) > 8) {
             return false;
         }
         while (count($first) < 8) {
             array_push($first, '0');
         }
         array_splice($first, 8 - count($second), 8, $second);
         $aIP = $first;
         unset($first, $second);
     } else {
         $aIP = explode(':', $aIP[0]);
     }
     $c = count($aIP);
     if ($c != 8) {
         return false;
     }
     //      All the pieces should be 16-bit hex strings. Are they?
     foreach ($aIP as $piece) {
         if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece))) {
             return false;
         }
     }
     return $original;
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:60,代码来源:IPv6.php

示例5: build

 public function build($data)
 {
     list($team, $year) = $data;
     $redirect = path('player_attach_ncaa_ids', array('slug' => $team->getSlug()));
     $this->setPlayerNcaaIdsForTeam($team, $year);
     $form = $this->form = $this->CI->form->open(path('player_attach_ncaa_ids_for_year', array('slug' => $team->getSlug(), 'year' => $year)), null, 'class="form-horizontal"');
     $globalError = false;
     foreach ($team->getPlayers($year) as $player) {
         $class = '';
         if (count($player->getAllNcaaIds())) {
             foreach ($player->getAllNcaaIds() as $ncaaId) {
                 if (in_array($ncaaId, array_splice(array_keys($this->players), 1))) {
                     $class = 'success';
                 }
             }
             if (!$class) {
                 $class = 'error';
                 $globalError = true;
             }
         } else {
             $class = '';
             if (!$this->matchNameInArray($player)) {
                 $globalError = true;
             }
         }
         $form->html(sprintf('<div class="control-group %s form-inline"><label class="control-label">%s, %s</label>', $class, $player->getLastName(), $player->getFirstName()))->select(sprintf('player[%s]', $player->getId()), $this->players, null, $this->matchNameInArray($player), null, 'class="span8"')->html('</div>');
     }
     $form->html('<div class="form-actions">')->submit('Save Changes', 'submit', 'class="btn btn-primary"')->html('</div>')->model('document', 'validate', 'team/edit')->onsuccess('redirect', $redirect);
     if (!$globalError) {
         $this->save($form, $data, $redirect);
     }
     return $form;
 }
开发者ID:bigjoevtrj,项目名称:codeigniter-bootstrap,代码行数:33,代码来源:player_attach_ncaa_ids.php

示例6: handle_api_requests

 public function handle_api_requests()
 {
     WPI_Log::get_instance()->log('wpi api request : ' . 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     global $wp;
     if (isset($_GET['wpi-api'])) {
         $wp->query_vars['wpi-api'] = $_GET['wpi-api'];
     }
     if (isset($wp->query_vars['wpi-api'])) {
         $this->server = new WPI_Server();
         $n = strpos($wp->query_vars['wpi-api'], '/');
         if (!empty($n)) {
             $qs = explode('/', $wp->query_vars['wpi-api']);
             $api = $qs[0];
             $method = $qs[1];
             if (file_exists(WPI_DIR . '/api/class-wpi-' . $api . ".php")) {
                 include_once WPI_DIR . '/api/class-wpi-' . $api . ".php";
                 $args = array_splice($qs, 2, 2);
                 call_user_func_array(array($api, $method), $args);
             } else {
                 $this->server->response_failure('api not found !');
             }
         } else {
             $api = $wp->query_vars['wpi-api'];
             if (file_exists(WPI_DIR . '/api/class-wpi-' . $api . '.php')) {
                 include_once WPI_DIR . '/api/class-wpi-' . $api . '.php';
             } else {
                 $this->server->response_failure('api not found !');
             }
         }
         WPI_Log::get_instance()->close();
         die;
     }
 }
开发者ID:Jeremaihloo,项目名称:Woo-Public-Interface,代码行数:33,代码来源:wpi-api.php

示例7: handleRequest

 public function handleRequest($request)
 {
     if (empty($this->catchAll)) {
         list($route, $params) = $request->resolve();
     } else {
         $route = $this->catchAll[0];
         $params = array_splice($this->catchAll, 1);
     }
     try {
         LuLu::trace("Route requested: '{$route}'", __METHOD__);
         $this->requestedRoute = $route;
         $actionsResult = $this->runAction($route, $params);
         $result = $actionsResult instanceof ActionResult ? $actionsResult->result : $actionsResult;
         if ($result instanceof \yii\web\Response) {
             return $result;
         } else {
             $response = $this->getResponse();
             if ($result !== null) {
                 $response->data = $result;
             }
             return $response;
         }
     } catch (InvalidRouteException $e) {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'), $e->getCode(), $e);
     }
 }
开发者ID:cookedsteak,项目名称:lulucms2,代码行数:26,代码来源:BaseApplication.php

示例8: dequeue

 /**
  * Dequeues one or several values from the beginning of the Queue
  *
  * When called without argument, returns a single value, else returns an array.
  * If there is not anough elements in the queue, all the elements are returned
  * without raising any error.
  *
  * @param int $quantity
  *
  * @return mixed
  */
 public function dequeue($quantity = 1)
 {
     if (!func_num_args()) {
         return array_pop($this->elements);
     }
     return array_splice($this->elements, max(0, count($this->elements) - $quantity), $quantity, []);
 }
开发者ID:kgodet,项目名称:Aldente,代码行数:18,代码来源:Queue.php

示例9: get_files

 function get_files($dir)
 {
     static $extension = null;
     if (!$extension) {
         $extension = pathinfo(__FILE__, PATHINFO_EXTENSION);
     }
     $files = array();
     if ($dh = opendir($dir)) {
         while (($file = readdir($dh)) !== false) {
             if (substr($file, 0, 1) != '.') {
                 $files[] = "{$dir}/{$file}";
             }
         }
         closedir($dh);
         usort($files, array(&$this, 'sort_files'));
         foreach ($files as $file) {
             if (is_dir($file)) {
                 array_splice($files, array_search($file, $files), 0, $this->get_files($file));
             }
             if (pathinfo($file, PATHINFO_EXTENSION) != $extension) {
                 unset($files[array_search($file, $files)]);
             }
         }
     }
     return $files;
 }
开发者ID:yusufchang,项目名称:app,代码行数:26,代码来源:unit_test.php

示例10: topEarners

 /**
  * Function will calculate the top publisher results
  * from the performance table
  * @return  Array of Top Earners
  */
 public static function topEarners($users, $dateQuery = [], $count = 10)
 {
     $pubClicks = [];
     $result = [];
     foreach ($users as $u) {
         $perf = \Performance::calculate($u, $dateQuery);
         $clicks = $perf['clicks'];
         if ($clicks === 0) {
             continue;
         }
         if (!array_key_exists($clicks, $pubClicks)) {
             $pubClicks[$clicks] = [];
         }
         $pubClicks[$clicks][] = AM::toObject(['name' => $u->name, 'clicks' => $clicks]);
     }
     if (count($pubClicks) === 0) {
         return $result;
     }
     krsort($pubClicks);
     array_splice($pubClicks, $count);
     $i = 0;
     foreach ($pubClicks as $key => $value) {
         foreach ($value as $u) {
             $result[] = $u;
             $i++;
             if ($i >= $count) {
                 break 2;
             }
         }
     }
     return $result;
 }
开发者ID:vNative,项目名称:vnative,代码行数:37,代码来源:user.php

示例11: main

 /**
  * Main function, adding the item to input menuItems array
  *
  * @param ClickMenu $backRef References to parent clickmenu objects.
  * @param array $menuItems Array of existing menu items accumulated. New element added to this.
  * @param string $table Table name of the element
  * @param int $uid Record UID of the element
  * @return array Modified menuItems array
  */
 public function main(&$backRef, $menuItems, $table, $uid)
 {
     $localItems = array();
     if (!$backRef->cmLevel && $uid > 0 && $GLOBALS['BE_USER']->check('modules', 'web_txversionM1')) {
         // Returns directly, because the clicked item was not from the pages table
         if (in_array('versioning', $backRef->disabledItems) || !$GLOBALS['TCA'][$table] || !$GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
             return $menuItems;
         }
         // Adds the regular item
         $LL = $this->includeLL();
         // "Versioning" element added:
         $url = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txversionM1', array('table' => $table, 'uid' => $uid));
         $localItems[] = $backRef->linkItem($GLOBALS['LANG']->getLLL('title', $LL), $backRef->excludeIcon($this->iconFactory->getIcon('actions-version-open', Icon::SIZE_SMALL)->render()), $backRef->urlRefForCM($url), true);
         // Find position of "delete" element:
         $c = 0;
         foreach ($menuItems as $k => $value) {
             $c++;
             if ($k === 'delete') {
                 break;
             }
         }
         // .. subtract two (delete item + divider line)
         $c -= 2;
         // ... and insert the items just before the delete element.
         array_splice($menuItems, $c, 0, $localItems);
     }
     return $menuItems;
 }
开发者ID:hlop,项目名称:TYPO3.CMS,代码行数:37,代码来源:VersionClickMenu.php

示例12: schedulingTasksFroMinTimeRang

 public static function schedulingTasksFroMinTimeRang(array $tasks, $minTimeRange, $maxInterval)
 {
     $count = count($tasks);
     if ($maxInterval * $count > $minTimeRange) {
         $repeat = 0;
         do {
             $repeat++;
             $maxInterval = $repeat * $minTimeRange / $count;
             $maxInterval = floor($maxInterval);
         } while ($maxInterval < 1);
     }
     $times = [];
     $lastTime = 0;
     do {
         $times[] = $lastTime;
         $lastTime += $maxInterval;
     } while ($lastTime < $minTimeRange);
     $timesCount = count($times);
     $repeat = $count / $timesCount;
     $repeat = floor($repeat);
     $rest = $count - $timesCount * $repeat;
     $scheduledData = [];
     foreach ($times as $index => $time) {
         $itemRepeat = $repeat;
         if ($rest >= $index + 1) {
             $itemRepeat++;
         }
         $scheduledData[$time] = array_splice($tasks, 0, $itemRepeat);
         if (empty($tasks)) {
             break;
         }
     }
     return $scheduledData;
 }
开发者ID:ashmna,项目名称:MedDocs,代码行数:34,代码来源:Scheduling.php

示例13: _beforeToHtml

 /**
  * Load the RSS feed and items before the block is rendered
  *
  */
 protected function _beforeToHtml()
 {
     parent::_beforeToHtml();
     $this->setFeedReady(false);
     if ($this->getFeedUrl() !== false) {
         if (($feed = $this->_getRssFeed($this->getFeedUrl())) !== false) {
             $this->setFeedTitle($feed->getTitle());
             $this->setFeedLink($feed->getLink());
             $this->setFeedDescription($feed->getDescription());
             $buffer = $feed->getItem();
             if (count($buffer) > 0) {
                 if (!isset($buffer[0]) && isset($buffer['title'])) {
                     $buffer = array($buffer);
                 }
                 $items = array();
                 foreach ($buffer as $item) {
                     if (($item = $this->_prepareFeedItem($item)) !== false) {
                         $items[] = $item;
                         $this->setFeedReady(true);
                     }
                 }
                 if (count($items) > $this->getMaxFeedItems()) {
                     $items = array_splice($items, 0, $this->getMaxFeedItems());
                 }
                 $this->setFeedItems($items);
             }
         }
     }
     return $this;
 }
开发者ID:LiamMcArthur,项目名称:extension-fishpig-wordpress-integration,代码行数:34,代码来源:Abstract.php

示例14: replace

 public function replace($content, $replace = '*')
 {
     // 计算文本内容长度
     $cLength = mb_strlen($content, 'UTF-8');
     $words = array();
     // 对每个字符进行关键词检查
     for ($i = 0; $i < $cLength; $i++) {
         $words[] = mb_substr($content, $i, 1, 'UTF-8');
     }
     // 对每个字符进行关键词检查
     foreach ($words as $i => $word) {
         // 首字符是否在过滤关键词分类中存在
         if (isset($this->classArr[$word])) {
             // 如果存在则将该分类下的所有关键词遍历,依次对文本内容中与每一个关键词位置长度相对应的字符串进行比较
             foreach ($this->classArr[$word] as $v) {
                 // 过滤关键词长度
                 $filterWordLength = mb_strlen($v, 'UTF-8');
                 // 获取文本中对应位置,相同长度的字符串
                 $contentEqPostionWord = mb_substr($content, $i, $filterWordLength, 'UTF-8');
                 // 对两个字符串进行比较
                 if ($contentEqPostionWord == $v) {
                     // 如果相同,则将该段字符串替换成相应长度的 *
                     array_splice($words, $i, $filterWordLength, array_fill(0, $filterWordLength, $replace));
                 }
             }
         }
     }
     return implode('', $words);
 }
开发者ID:emilymwang8,项目名称:ajk-broker,代码行数:29,代码来源:FilterWords.php

示例15: addPlaylistAt

 /**
  * Add another playlist into the current starting from $offset. Invalid items from $playlist
  * will be silently filtered out. This method assigns existing items to new offsets
  *
  * @param integer $offset
  * @param Streamwide_Engine_Media_Playlist $playlist
  * @return void
  */
 public function addPlaylistAt($offset, Streamwide_Engine_Media_Playlist $playlist)
 {
     if ($playlist->isEmpty()) {
         return;
     }
     array_splice($this->_collection, $offset, 0, $playlist->toArray());
 }
开发者ID:cwcw,项目名称:cms,代码行数:15,代码来源:Playlist.php


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