本文整理汇总了PHP中SplFixedArray::count方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFixedArray::count方法的具体用法?PHP SplFixedArray::count怎么用?PHP SplFixedArray::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFixedArray
的用法示例。
在下文中一共展示了SplFixedArray::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: keep
/**
* @param int $numberOfCardsToKeep
*
* @return HandInterface
*/
public function keep(int $numberOfCardsToKeep) : HandInterface
{
if ($this->cards->count() <= $numberOfCardsToKeep) {
return $this;
}
return new self(...array_slice($this->getCards(), 0, $numberOfCardsToKeep));
}
示例2: getNotificacoes
/**
* @return \SplStack
*/
public function getNotificacoes()
{
$notificacoes = new \SplStack();
for ($i = 0; $i < $this->listaDeItens->count(); $i++) {
$notificacoes->push($this->listaDeItens[$i]->notify());
}
return $notificacoes;
}
示例3: sort
/**
* {@inheritdoc}
*/
public function sort(\SplFixedArray $array)
{
$length = $array->count();
for ($i = 1; $i < $length; $i++) {
$key = $array[$i];
$j = $i - 1;
while ($j >= 0 && $array[$j] > $key) {
$array[$j + 1] = $array[$j];
$j--;
}
$array[$j + 1] = $key;
}
return $array;
}
示例4: sort
/**
* {@inheritdoc}
*/
public function sort(\SplFixedArray $array)
{
$length = $array->count();
for ($i = 0; $i < $length - 1; $i++) {
$smallest = $i;
for ($j = $i + 1; $j < $length; $j++) {
if ($array[$j] < $array[$smallest]) {
$smallest = $j;
}
}
$tmp = $array[$i];
$array[$i] = $array[$smallest];
$array[$smallest] = $tmp;
}
return $array;
}
示例5: selectionsort
function selectionsort(SplFixedArray $arr)
{
$sIndex = 0;
$smallestIndex = 0;
$tmp = null;
$count = $arr->count();
while ($sIndex < $count) {
$smallestIndex = $sIndex;
for ($i = $sIndex; $i < $count; $i++) {
if ($arr[$i] < $arr[$smallestIndex]) {
$smallestIndex = $i;
}
}
if ($sIndex < $smallestIndex) {
$tmp = $arr[$smallestIndex];
$arr[$smallestIndex] = $arr[$sIndex];
$arr[$sIndex] = $tmp;
}
$sIndex++;
}
}
示例6: SplFixedArray
<?php
$array = new SplFixedArray(5);
echo $array->count(3);
示例7: count
/**
* Returns the number of objects in the collection
*
* @return Natural
*/
public function count()
{
return new Natural($this->items->count());
}
示例8: count
/**
* @return int
*/
public function count()
{
return $this->set->count();
}
示例9: SplFixedArray
<?php
echo "Commit from Mint command line";
$array = new SplFixedArray(5);
echo $array->count();
$array->setSize(10);
echo '<br>' . $array->count();
$array[4] = 'lalala';
$array[1] = 'bababa';
$array->next();
echo '<br>' . $array->current();
echo '<br>' . $array->key();
echo "commit from mint PhpStorm";
示例10: __construct
/**
* Constructor
* @param \Segment\Model\SearchValues|\Segment\Model\Expression $value1
* @param \Segment\Model\SearchValues|\Segment\Model\Expression $values Variable-length variable.
*/
public function __construct($value1, ...$values)
{
$count = count($values);
$v_arr = new \SplFixedArray($count + 1);
$v_arr->offsetSet(0, $value1);
for ($i = 0; $i < $count; $i++) {
$v_arr->offsetSet($i + 1, $values[$i]);
}
$this->values = $v_arr;
$this->count = $v_arr->count();
}
示例11: valid
/**
* (PHP 5 >= 5.0.0)<br/>
* Checks if current position is valid
*
* @link http://php.net/manual/en/iterator.valid.php
* @return boolean The return value will be casted to boolean and then evaluated.
* Returns true on success or false on failure.
*/
public function valid()
{
return $this->index < $this->rawData->count() || $this->index < $this->objectData->count();
}
示例12: SplFixedArray
<?php
/**
* spl数据结构demo
* 阵列 SplFixedArray
*
*/
// 定义一个长度为5的阵列
$array = new SplFixedArray(5);
$array[1] = 2;
$array[3] = 'value2';
// count()
// 阵列长度
$array->count();
// key()
// 获得当前节点的索引
$array->key();
// valid()
// 判断是否还存在值
$array->valid();
// rewind()
// 回到初始节点
$array->rewind();
// current()
// 获得当前节点
$array->current();
// next()
// 指针移动到下一个节点
$array->next();
// setSize(int $size)
// 重新设置阵列数组的大小
示例13: count
public function count()
{
return -parent::count();
}
示例14: SplFixedArray
<?php
// Create a fixed array
$fixedArray = new SplFixedArray(5);
// Fill it up
for ($i = 0; $i < 5; $i++) {
$fixedArray[$i] = "PHPNW Testfest";
}
// Test count() returns correct error when parameters are passed.
$fixedArray->count(1);
示例15: SplFixedArray
<?php
#Examples
#Example #1 SplFixedArray usage example
// Initialize the array with a fixed length
$array = new SplFixedArray(5);
$array[1] = 2;
$array[4] = "foo";
echo "<pre>";
var_dump($array[0]);
// NULL
var_dump($array[1]);
// int(2)
var_dump($array["4"]);
// string(3) "foo"
echo "\n Array Count defined : " . $array->count() . "\n";
// Increase the size of the array to 10
$array->setSize(10);
// getting the array size
echo "\n getSize :" . $array->getSize() . "\n";
$array[9] = "asdf";
echo "\n Array Count increase : " . $array->count() . "\n";
// Shrink the array to a size of 2
$array->setSize(2);
echo "\n Array Count shrink : " . $array->count() . "\n";
// The following lines throw a RuntimeException: Index invalid or out of range
try {
var_dump($array["non-numeric"]);
} catch (RuntimeException $re) {
echo "RuntimeException: " . $re->getMessage() . "\n";
}