本文整理汇总了PHP中ArrayIterator::seek方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayIterator::seek方法的具体用法?PHP ArrayIterator::seek怎么用?PHP ArrayIterator::seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayIterator
的用法示例。
在下文中一共展示了ArrayIterator::seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSeek
function testSeek()
{
$iterator = new ArrayIterator([0, 5, 2, 6]);
$iterator->rewind();
$iterator->seek(3);
$this->assertEquals(6, $iterator->current());
$iterator->seek(1);
$this->assertEquals(5, $iterator->current());
$iterator->seek(2);
$this->assertEquals(2, $iterator->current());
$iterator->seek(0);
$this->assertEquals(0, $iterator->current());
$iterator->seek(3);
$this->assertEquals(6, $iterator->current());
}
示例2: ReplaceChunk
/**
* Replace portion of the string
*
* @deprecated
*
* @param integer $index
* @param string $value
* @param integer $start
* @param integer $length
*
* @access public
* @return void
*/
public function ReplaceChunk($index, $value, $start = 0, $length = null)
{
if (null !== $length) {
$this->length = $length;
}
switch (true) {
case is_string($value):
$this->temp_string = new \ArrayIterator(str_split($value));
if (null === $length) {
$this->length = strlen($value);
}
break;
case $value instanceof \ArrayIterator:
$this->temp_string = $value;
if (null === $length) {
$this->length = $value->count();
}
break;
case is_array($value):
$this->temp_string = new \ArrayIterator($value);
if (null === $length) {
$this->length = count($value);
}
break;
default:
throw new \Exception('Invalid data type', 101);
}
$this->temp_string->seek($start);
for ($i = $start; $i < $this->length; $i++) {
$this->offsetSet($index, $this->temp_string->current());
$index++;
$this->temp_string->next();
}
$this->temp_string = null;
}
示例3: seek
/**
* (PHP 5 >= 5.1.0)<br/>
* Seeks to a position
* @link http://php.net/manual/en/seekableiterator.seek.php
* @param int $position <p>
* The position to seek to.
* </p>
* @return void
* @throws MIMException
*/
public function seek($position)
{
if ($position == NULL) {
throw new MIMException("Can't seek to a NULL position", 550);
}
$this->iterator->seek($position);
}
示例4: getByPosition
/**
* Gets item by it`s position
* @param integer $position
* @return mixed
*/
private function getByPosition($position)
{
$key = $this->_list->key();
$this->_list->seek($position);
$item = $this->_list->current();
$this->_list->seek($key);
return $item;
}
示例5: omg
function omg()
{
$itr = new ArrayIterator($vals);
$itr->seek($random);
$city = $itr->current();
$country = $itr->key();
echo $country;
return $city;
}
示例6: seek
/**
* nastaví podle vnitřního ukazatele
*/
public function seek($pointer)
{
$pointer = (int) $pointer;
try {
parent::seek($pointer);
$this->pointer = $pointer;
} catch (\OutOfBoundsException $e) {
if ($this->pointer != -1) {
throw $e;
}
}
}
示例7: filter
/**
* @inheritDoc
*/
public function filter(RoundGearsInterface $previousRoundGears)
{
$advance = $previousRoundGears->getRound()->getSetup()->getAdvance();
// -1 = all
$leaderBoard = $previousRoundGears->getLeaderBoard();
$result = array();
$groupNumbers = $leaderBoard->getGroupNumbers();
foreach ($groupNumbers as $groupNumber) {
$result[$groupNumber] = array();
}
$groupNumberStepped = function ($step) use($groupNumbers) {
$it = new \ArrayIterator($groupNumbers);
$it->seek($step % $it->count());
return $it->current();
};
$players = $leaderBoard->getEntries($advance);
$step = 0;
foreach ($groupNumbers as $groupNumber) {
$groupAdvance = -1 == $advance ? count($players[$groupNumber]) : $advance;
for ($i = 0; $i < $groupAdvance; ++$i) {
$result[$groupNumberStepped($step + $i)][] = $players[$groupNumber][$i]->getPlayer();
}
$step += $this->getSteps();
}
// $step = 0;
// for ($i = 0; $i < $advance; ++$i) {
// foreach ($groupNumbers as $groupNumber) {
// $result[$groupNumberStepped($step+1)][] = $players[$groupNumber][$i];
// }
//
// $step += $this->getSteps();
// }
// dump($players, $result);
// TODO implement input step : filter
// throw new \Exception('TODO');
return $result;
}
示例8: gettext
</th>
<th><?php
echo gettext('Status');
?>
</th>
<th><?php
echo gettext('Planned');
?>
</th>
</tr>
</thead>
<tbody class="form_data_line_tbody item_relation_values" >
<?php
$count = 0;
$item_relation_object_ai = new ArrayIterator($item_relation_object);
$item_relation_object_ai->seek($position);
while ($item_relation_object_ai->valid()) {
$inv_item_relation = $item_relation_object_ai->current();
if (!empty(${$class}->from_item_id_m)) {
$from_item_i = item::find_by_item_id_m(${$class}->from_item_id_m);
if ($from_item_i) {
${$class}->from_item_number = $from_item_i->item_number;
} else {
${$class}->from_item_number = null;
}
} else {
${$class}->from_item_number = null;
}
if (!empty(${$class}->to_item_id_m)) {
$to_item_i = item::find_by_item_id_m(${$class}->to_item_id_m);
if ($to_item_i) {
示例9: Flight
<th>Destination</th>
<th>Boarding Date</th>
<th>Arrival Date</th>
<th>Boarding Time</th>
<th>Arrival Time</th>
<th>Stops</th>
<th>Price Rate</th>
<th>Status</th>
<th>#</th>
</tr>
<?php
for ($var = 0; $var < $flightList->count(); $var++) {
$flight = new Flight();
$flightList->seek($var);
$flight = $flightList->current();
$checkFlight = ContextManager::$Model->flight != null ? ContextManager::$Model->flight : new Flight();
$checked = "";
if ($checkFlight->checked == true && $flight->Id == $checkFlight->Id) {
//echo $flight->checked;
$checked = "checked='checked'";
}
$status = "";
if ($flight->status == 0 || $flight->status == '0') {
$status = "passive";
} else {
$status = "active";
}
$name = $aplanes->GetName($flight->planeID);
echo "<tr>\r\n <td>{$var}</td>\r\n <td>{$name}</td>\r\n <td>{$flight->from}</td>\r\n <td>{$flight->to}</td>\r\n <td>{$flight->deptureDate}</td>\r\n <td>{$flight->landindDate}</td>\r\n <td>{$flight->boardingTime}</td>\r\n <td>{$flight->Landingtime}</td>\r\n <td>{$flight->stops}</td>\r\n <td>{$flight->ticketPrice}</td>\r\n <td>{$flight->seats}</td>\r\n <td>{$status}</td>\r\n <td><input type='checkbox' value='{$flight->Id}' name='chkflights[]' {$checked} ></td>\r\n </tr>\r\n ";
示例10: gettext
</th>
<th><?php
echo gettext('Task Status');
?>
</th>
<th><?php
echo gettext('CIP Asset');
?>
</th>
</tr>
</thead>
<tbody class="form_data_line_tbody">
<?php
$count = 0;
$prj_project_line_object_ai = new ArrayIterator($prj_project_line_object);
$prj_project_line_object_ai->seek($position);
while ($prj_project_line_object_ai->valid()) {
$prj_project_line = $prj_project_line_object_ai->current();
?>
<tr class="prj_project_line<?php
echo $count;
?>
">
<td><?php
$f->seq_field_d($count);
?>
</td>
<td><?php
echo $f->text_field('task_number2', ${$class_second}->task_number, '', '', 'task_number');
?>
示例11: gettext
<th><?php
echo gettext('Quantity');
?>
#</th>
<th><?php
echo gettext('Line Amount');
?>
</th>
</tr>
</thead>
<tbody class="form_data_line_tbody pos_transaction_line_values" >
<?php
// pa($pos_transaction_line_object);
$count = 0;
$pos_transaction_line_object_ai = new ArrayIterator($pos_transaction_line_object);
$pos_transaction_line_object_ai->seek($position);
while ($pos_transaction_line_object_ai->valid()) {
$pos_transaction_line = $pos_transaction_line_object_ai->current();
?>
<tr class="pos_transaction_line<?php
echo $count;
?>
">
<td><?php
$f->text_field_wid2('item_number');
?>
</td>
<td><?php
echo $f->number_field('unit_price', ${$class_second}->unit_price, '', '', 'medium');
?>
示例12: getDirectoryItemList
protected function getDirectoryItemList($path, $start, $numberOfItems, array $filterMethods, $itemHandlerMethod, $itemRows = array(), $recursive = FALSE)
{
$realPath = rtrim($this->absoluteBasePath . trim($path, '/'), '/') . '/';
if (!is_dir($realPath)) {
throw new \InvalidArgumentException('Cannot list items in directory ' . $path . ' - does not exist or is no directory', 1314349666);
}
if ($start > 0) {
$start--;
}
// Fetch the files and folders and sort them by name; we have to do
// this here because the directory iterator does return them in
// an arbitrary order
$items = $this->getFileAndFoldernamesInPath($realPath, $recursive);
natcasesort($items);
$iterator = new \ArrayIterator($items);
if ($iterator->count() == 0) {
return array();
}
$iterator->seek($start);
if ($path !== '' && $path !== '/') {
$path = '/' . trim($path, '/') . '/';
}
// $c is the counter for how many items we still have to fetch (-1 is unlimited)
$c = $numberOfItems > 0 ? $numberOfItems : -1;
$items = array();
while ($iterator->valid() && ($numberOfItems == 0 || $c > 0)) {
// $iteratorItem is the file or folder name
$iteratorItem = $iterator->current();
// go on to the next iterator item now as we might skip this one early
$iterator->next();
$identifier = $path . $iteratorItem;
if ($this->applyFilterMethodsToDirectoryItem($filterMethods, $iteratorItem, $identifier, $path) === FALSE) {
continue;
}
if (isset($itemRows[$identifier])) {
list($key, $item) = $this->{$itemHandlerMethod}($iteratorItem, $path, $itemRows[$identifier]);
} else {
list($key, $item) = $this->{$itemHandlerMethod}($iteratorItem, $path);
}
if (empty($item)) {
continue;
}
$items[$key] = $item;
// Decrement item counter to make sure we only return $numberOfItems
// we cannot do this earlier in the method (unlike moving the iterator forward) because we only add the
// item here
--$c;
}
return $items;
}
示例13: getDirectoryItemList
/**
* Generic wrapper for extracting a list of items from a path.
*
* @param string $folderIdentifier
* @param int $start The position to start the listing; if not set, start from the beginning
* @param int $numberOfItems The number of items to list; if set to zero, all items are returned
* @param array $filterMethods The filter methods used to filter the directory items
* @param bool $includeFiles
* @param bool $includeDirs
* @param bool $recursive
* @param string $sort Property name used to sort the items.
* Among them may be: '' (empty, no sorting), name,
* fileext, size, tstamp and rw.
* If a driver does not support the given property, it
* should fall back to "name".
* @param bool $sortRev TRUE to indicate reverse sorting (last to first)
* @return array
* @throws \InvalidArgumentException
*/
protected function getDirectoryItemList($folderIdentifier, $start = 0, $numberOfItems = 0, array $filterMethods, $includeFiles = true, $includeDirs = true, $recursive = false, $sort = '', $sortRev = false)
{
$folderIdentifier = $this->canonicalizeAndCheckFolderIdentifier($folderIdentifier);
$realPath = $this->getAbsolutePath($folderIdentifier);
if (!is_dir($realPath)) {
throw new \InvalidArgumentException('Cannot list items in directory ' . $folderIdentifier . ' - does not exist or is no directory', 1314349666);
}
if ($start > 0) {
$start--;
}
$items = $this->retrieveFileAndFoldersInPath($realPath, $recursive, $includeFiles, $includeDirs, $sort, $sortRev);
$iterator = new \ArrayIterator($items);
if ($iterator->count() === 0) {
return array();
}
$iterator->seek($start);
// $c is the counter for how many items we still have to fetch (-1 is unlimited)
$c = $numberOfItems > 0 ? $numberOfItems : -1;
$items = array();
while ($iterator->valid() && ($numberOfItems === 0 || $c > 0)) {
// $iteratorItem is the file or folder name
$iteratorItem = $iterator->current();
// go on to the next iterator item now as we might skip this one early
$iterator->next();
if (!$this->applyFilterMethodsToDirectoryItem($filterMethods, $iteratorItem['name'], $iteratorItem['identifier'], $this->getParentFolderIdentifierOfIdentifier($iteratorItem['identifier']))) {
continue;
}
$items[$iteratorItem['identifier']] = $iteratorItem['identifier'];
// Decrement item counter to make sure we only return $numberOfItems
// we cannot do this earlier in the method (unlike moving the iterator forward) because we only add the
// item here
--$c;
}
return $items;
}
示例14: ArrayIterator
?>
<?php
$iterator = new ArrayIterator(array('recipe'=>'pancakes', 'egg', 'milk', 'flour'));
$itCnt = $iterator->count();
echo $itCnt . PHP_EOL;
$iterator->append("water");
$iterator->ksort();
while($iterator->valid()){
echo "Key : ". $iterator->key() . ", Value: " .$iterator->current() . PHP_EOL;
$iterator->next();
}
if($iterator->offsetExists(9)){
$iterator->seek(3);
}
else{
$iterator->seek($itCnt);
echo $iterator->offsetGet('recipe') . PHP_EOL;
}
echo "[$itCnt]" . PHP_EOL;
echo PHP_EOL . "Key : ". $iterator->key() . ", Value: " .$iterator->current() . PHP_EOL;
var_dump(iterator_count($iterator));
?>
示例15: gettext
</th>
<th><?php
echo gettext('Start Date');
?>
</th>
<th><?php
echo gettext('End Date');
?>
</th>
</tr>
</thead>
<tbody class="form_data_line_tbody">
<?php
$linecount = 0;
$option_line_object_ai = new ArrayIterator($option_line_object);
$option_line_object_ai->seek($position);
while ($option_line_object_ai->valid()) {
$option_line = $option_line_object_ai->current();
?>
<tr class="option_line<?php
echo $linecount;
?>
">
<td><?php
$f->seq_field_d($linecount);
?>
</td>
<td><?php
echo form::status_field($option_line->status);
?>