本文整理汇总了PHP中ArrayIterator::count方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayIterator::count方法的具体用法?PHP ArrayIterator::count怎么用?PHP ArrayIterator::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayIterator
的用法示例。
在下文中一共展示了ArrayIterator::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
*
* @param <type> $table
* @param ArrayIterator $params
* @return ArrayObject
*/
public function search($table, ArrayIterator $params)
{
$this->searchParams = $params;
$this->join();
if ($table == "analysis") {
$this->statements->remove("type_event");
}
$statement = "SELECT this_.* " . $this->selectAttributes() . " FROM {$table} this_ ";
$statement .= $this->join();
$i = 0;
$this->searchParams->rewind();
if ($this->searchParams->count() > 0 && !$this->searchParams->offsetExists('true')) {
$statement .= " WHERE ";
}
while ($this->searchParams->valid()) {
if ($this->statements->containsKey($this->searchParams->key())) {
if ($i++ > 0) {
$statement .= " AND ";
}
$clause = $this->statements->get($this->searchParams->key());
$statement .= str_replace(":" . $this->searchParams->key(), "'" . $this->searchParams->current() . "'", $clause['where']);
}
$this->searchParams->next();
}
return $this->getObject($statement . " ORDER BY this_.date DESC, this_.id DESC");
}
示例2: getRows
/**
* @param int $groupPosition
* @return array
*/
public function getRows($groupPosition)
{
$rows = [];
$columns = $this->getAllAggregationColumns();
if ($groupPosition == Group::GROUP_VERTICAL) {
foreach ($this->arrayIterator as $current) {
$cols = [$this->getRealEntityName((int) $current['key'])];
foreach ($columns as $aggrIndex => $aggrFieldNames) {
$aggregationData = $this->extractDataFromAggregation($aggrIndex, $aggrFieldNames, $current);
foreach ($aggregationData as $value) {
array_push($cols, $value);
}
}
$rows[] = $cols;
}
} else {
$assocAggregationList = ArrayHelper::index($this->aggregationList, 'index');
foreach ($columns as $aggrIndex => $aggrFieldNames) {
$rows[] = ['colspan' => $this->arrayIterator->count() + 1, 'value' => $assocAggregationList[$aggrIndex]['title']];
foreach ($aggrFieldNames as $fieldName) {
$cols = [$fieldName];
foreach ($this->arrayIterator as $current) {
$cols[] = $this->findValue($current[$aggrIndex], $fieldName);
}
$rows[] = $cols;
}
}
}
$this->arrayIterator->rewind();
return $rows;
}
示例3: solve
/**
* {@inheritdoc}
*/
public function solve(\Iterator $operations, \Iterator $items)
{
// search for all UnaryOperations
$tempResult = $items;
$unaryChain = new \ArrayIterator();
foreach ($operations as $operation) {
// collect all unary operators
if ($operation instanceof IntermediateOperationInterface) {
$unaryChain->append($operation);
} else {
// execute all the collected unary operations
if ($unaryChain->count() > 0) {
$tempResult = $this->solveIntermediateOperationChain($unaryChain, $tempResult);
$unaryChain = new \ArrayIterator();
}
// execute full set operations (like sort)
if ($operation instanceof FullSetOperationInterface) {
$tempResult = $operation->apply($tempResult);
}
}
}
// resolve the rest of the unary operation
if ($unaryChain->count() > 0) {
$tempResult = $this->solveIntermediateOperationChain($unaryChain, $tempResult);
}
return $tempResult;
}
示例4: update
/**
* Update = $sql = "UPDATE tabla SET campo1 = ?, campo2 = ?, campo3 = ?
* WHERE idcampo = ?"
* $stm->bindValue(4, idValor);
*/
public function update($table, $data, $where, $id)
{
$result = null;
$iterator = new ArrayIterator($data);
$sql = "UPDATE {$table} SET ";
while ($iterator->valid()) {
$sql .= $iterator->key() . " = ?, ";
$iterator->next();
}
//Se elimina los dos ultimos caracteres (la coma y el espacio)
$sql = substr($sql, 0, -2);
$sql .= " WHERE {$where} = ?";
$stm = $this->_getDbh()->prepare($sql);
$i = 1;
foreach ($iterator as $param) {
$stm->bindValue($i, $param);
$i++;
}
/**
* Se asigna el bindValue para el parametro $id, como no esta contemplado en los ciclos del $data,
* se asigna en la posicion ($iterator->count()+1) y se le asigna el tipo de dato: PDO::PARAM_INT
*/
$stm->bindValue($iterator->count() + 1, $id, PDO::PARAM_INT);
$result = $stm->execute();
return $result;
}
示例5: __construct
/**
* Consumes data, turns the data into an array and stores it.
* This data can then be iterated.
*
* If count is provided, a custom count is set (for pagination
* purposes). Otherwise, the length of the data property is
* taken as the count value.
*
* @throws ResultException
*
* @param mixed $aData
* @param int $iCount
*/
public function __construct($aData, $iCount = null)
{
if ($iCount && !is_numeric($iCount)) {
throw new ResultException('Count must be numeric!');
}
if (!is_array($aData)) {
$aData = array($aData);
}
$this->oDataIterator = new \ArrayIterator($aData);
if ($aData === false) {
$this->iCount = 0;
} else {
$this->iCount = $iCount ? (int) $iCount : $this->oDataIterator->count();
}
$this->setSearchParams(array());
}
示例6: __construct
/**
* Default constructor to load the iterator. Override the parent
* LimitIterator as we don't want to return
*
* @access public
* @param ArrayIterator $it
*/
public function __construct(ArrayIterator $it, $page = 1, $limit = 10)
{
$this->_it = $it;
$this->_count = $it->count();
$this->setCurrentPage($page);
$this->setItemsPerPage($limit);
}
示例7: average
public function average(ArrayIterator $values)
{
$sum = 0;
while ($values->valid()) {
$sum += $values->current();
$values->next();
}
$values->rewind();
return round($sum / $values->count(), 2);
}
示例8: extractResponse
/**
* Extract response from Sender - depends on sender
*
* @param Response $response
*
* @return array('status_code', 'status_description', 'batch_id')
* @throws BulkSmsException
*/
public function extractResponse(Response $response)
{
$expected = array('status_code', 'status_description', 'batch_id');
$parts = explode('|', $response->body);
$it = new \ArrayIterator($parts);
if (count($expected) != $it->count()) {
throw new BulkSmsException("Count of BulkSMS response does not match expectations!. Return: " . $response->body);
}
$toreturn = [];
foreach ($expected as $item) {
$toreturn[$item] = $it->current();
$it->next();
}
return $toreturn;
}
示例9: container
/**
*
* @param Collection|Container $model
* @param int $arg
* @return string
*/
public function container(Container $model, $arg)
{
$string = '';
$cols = isset($model->config['columns']) && $model->config['columns'] > 0 ? $model->config['columns'] : 1;
$width = floor(12 / $cols);
$break = $arg;
$it = new ArrayIterator($model->getModels());
$item_left = $it->count();
while ($it->valid()) {
$column = '';
$break += ceil($item_left / $cols);
while ($it->valid() && $arg < $break) {
$column .= '<div class="row"><div class="col-md-12 list-item">' . $this->visit($it->current(), $arg) . '</div></div>';
$it->next();
$item_left--;
$arg++;
}
$cols--;
$string .= '<div class="col-md-' . $width . ' list-column">' . $column . '</div>';
}
return '<div class="row list">' . $string . '</div>';
}
示例10: extractResponse
/**
* Extract response from Sender - depends on sender
*
* @param Response $response
*
* @return array('msisdn', 'status_code')
* @throws BulkSmsException
*/
public function extractResponse(Response $response)
{
// dump the first 2 lines indicated by the string "0|Returns to follow\n\n"
$cleaned = substr($response->body, strlen("0|Returns to follow\n\n"), strlen($response->body));
$statusitems = explode("\n", $cleaned);
$siit = new \ArrayIterator(array_filter($statusitems));
$toreturn = [];
foreach ($siit as $item) {
$expected = array('msisdn', 'status_code');
$parts = explode('|', $item);
$it = new \ArrayIterator($parts);
if (count($expected) != $it->count()) {
throw new BulkSmsException("Count of BulkSMS response does not match expectations!. Return: " . $response->body);
}
$status = [];
foreach ($expected as $statusitem) {
$status[$statusitem] = $it->current();
$it->next();
}
$toreturn[] = $status;
}
return $toreturn;
}
示例11: 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;
}
示例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: array
echo "===Array===\n";
$a = array('zero' => 0, 'one' => 1, 'two' => 2);
$it = new ArrayIterator($a);
var_dump($it->count());
foreach ($it as $key => $val) {
echo "{$key}=>{$val}\n";
var_dump($it->count());
}
var_dump($it->count());
echo "===Object===\n";
class test
{
public $zero = 0;
protected $pro;
public $one = 1;
private $pri;
public $two = 2;
}
$o = new test();
$it = new ArrayIterator($o);
var_dump($it->count());
foreach ($it as $key => $val) {
echo "{$key}=>{$val}\n";
var_dump($it->count());
}
var_dump($it->count());
?>
===DONE===
<?php
exit(0);
示例15: Concat
/**
* Concatenates this with given $array
*
* @param Array $array
* @return Plinq
*/
public function Concat(array $array)
{
$this->rewind();
$array = new \ArrayIterator($array);
$array->rewind();
$total = $array->count();
for ($i = 0; $i < $total; $i++) {
$value = $array->current();
$key = $array->key();
$array->next();
$this[$key] = $value;
}
return $this;
}