/** * @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)); }
/** * @return \SplStack */ public function getNotificacoes() { $notificacoes = new \SplStack(); for ($i = 0; $i < $this->listaDeItens->count(); $i++) { $notificacoes->push($this->listaDeItens[$i]->notify()); } return $notificacoes; }
/** * {@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; }
/** * {@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; }
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++; } }
<?php $array = new SplFixedArray(5); echo $array->count(3);
/** * Returns the number of objects in the collection * * @return Natural */ public function count() { return new Natural($this->items->count()); }
/** * @return int */ public function count() { return $this->set->count(); }
<?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";
/** * 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(); }
/** * (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(); }
<?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) // 重新设置阵列数组的大小
public function count() { return -parent::count(); }
<?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);
<?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"; }
<?php $ar = new SplFixedArray(3); $ar[0] = 1; $ar[1] = 2; $ar[2] = 3; echo $ar->count(3);