/** * Returns true, if the item has any listeners. * * @return Boolean */ public function hasListeners() { if ($this->_listeners === null) { return false; } return $this->_listeners->count() > 0; }
/** * Returns the number or items in this collection * * @return int */ public function count() { if (!$this->_started) { $this->rewind(); } while ($this->valid()) { $this->next(); } return $this->_buffer->count(); }
// push($value) // 在结尾插入一个新值 $list->push('value1'); $list->push('value2'); $list->push('value3'); $list->push('value4'); $list->push('value5'); // pop() // 抛出结尾的一个元素,会使得链表结构减少一个 $list->pop(); // key() // 获得当前节点的索引值 $list->key(); // count() // 获得链表的数量 $list->count(); // rewind() // 将指针返回至初始节点 $list->rewind(); // current() // 获得当前节点 $list->current(); // top() // 返回最后一个节点的值 $list->top(); // bottom() // 返回第一个节点的值 $list->bottom(); // next() // 指针移到下一个节点 $list->next();
<?php $dll = new SplDoublyLinkedList(2); $dll->count(new SplDoublyLinkedList(2));
?> "> <i class="glyphicon glyphicon-shopping-cart icon-white"></i> Enviar al Carrito </a> </td> </tr> <?php } ?> </tbody> </table> <?php if ($listPila->count() == 0) { ?> <p>No se encuentran productos, por favor regrese e intente seleccionar otro producto.</p> <a class="btn btn-default btn-lg" href="products.php?pas=<?php echo $_GET['pas']; ?> &type=<?php echo $_GET['type']; ?> &select=1"> <i class="glyphicon glyphicon-chevron-left"></i> Seleccionar otro producto </a> <?php } ?>
echo "Mem real: " . __convert(memory_get_usage(true)) . "\n"; unset($array); echo "\n-- SplDoublyLinkedList \n"; echo "Mem usage: " . __convert(memory_get_usage()) . "\n"; echo "Mem real: " . __convert(memory_get_usage(true)) . "\n"; $s = microtime(true); $spl = new SplDoublyLinkedList(); for ($i = 0; $i < $v; $i++) { $spl->push($i); } try { $spl->offsetUnset(102); var_dump($spl->offsetGet(100)); var_dump($spl->offsetGet(102)); } catch (OutOfRangeException $e) { echo $e; } $e = microtime(true); echo "Count: " . $spl->count() . "\n"; echo "Elapsed time: " . ($e - $s) . " sec.\n"; echo "Mem usage: " . __convert(memory_get_usage()) . "\n"; echo "Mem real: " . __convert(memory_get_usage(true)) . "\n"; try { for ($i = 0; $i < $v; $i++) { $spl->pop(); } } catch (Exception $e) { } unset($spl); echo "\n"; }
<?php $dll = new SplDoublyLinkedList(); $dll->push(2); $dll->push(3); $dll->push(4); $dll->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO); foreach ($dll as $k => $v) { echo "{$k}=>{$v}\n"; } $dll->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO); foreach ($dll as $k => $v) { echo "{$k}=>{$v}\n"; } $dll->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_DELETE); var_dump($dll->count()); foreach ($dll as $k => $v) { echo "{$k}=>{$v}\n"; } var_dump($dll->count()); ?> ===DONE===
public function count() { return -parent::count(); }
/** * (PHP 5 >= 5.1.0) * Count elements of an object * * @link http://php.net/manual/en/countable.count.php * @return integer The custom count as an integer. */ public function count() { return $this->storage->count(); }
<?php $list = new SplDoublyLinkedList(); $c = $list->count('foo');
<?php $ll = new SplDoublyLinkedList(); $ll->push('1'); $ll->push('2'); $ll->push('3'); try { $ll->offsetUnset($ll->count() + 1); var_dump($ll); } catch (Exception $e) { echo $e->getMessage(); }
private function solve($formula) { $findSubFormula = false; $stringStart = 0; $stringLength = 0; $stack = new \SplStack(); $subFormulas = []; for ($i = 0; $i < strlen($formula); $i++) { $char = $formula[$i]; if ($this->isBracketOpen($char)) { if ($findSubFormula == false && $stack->count() == 0) { $stringStart = $i; } $stack->push(1); $findSubFormula = true; } if ($findSubFormula) { $stringLength++; } if ($this->isBracketClose($char)) { $stack->pop(); if ($stack->count() === 0 && $findSubFormula) { $subFormulas[substr($formula, $stringStart, $stringLength)] = substr($formula, $stringStart, $stringLength); $findSubFormula = false; $stringLength = 0; } } } if (count($subFormulas) > 0) { foreach ($subFormulas as &$subFormula) { $temp = trim(substr($subFormula, 1, strlen($subFormula) - 2)); $subFormula = $this->solve($temp); } $formula = str_replace(array_keys($subFormulas), array_values($subFormulas), $formula); } $elems = new \SplDoublyLinkedList(); array_map(function ($item) use($elems) { if ($item != ' ') { $elems->push($item); } }, explode(' ', $formula)); while ($elems->count() > 1) { $maxPriority = 0; $index = 0; foreach ($elems as $i => $el) { if (isset(static::$symbols[$el]) && static::$symbols[$el] > $maxPriority) { $maxPriority = static::$symbols[$el]; $index = $i; } } $this->process($index, $elems); } return $elems->pop(); }
<?php $dll = new SplDoublyLinkedList(); $dll->push('Never'); $dll->push('gonna'); $dll->push('give'); // at pos 0, shift everything up $dll->add(0, 'you'); // Should be the end $dll->add(4, 'up'); // Somewhere in the middle $dll->add(2, 'let'); try { // Key 12 is unaccessible $dll->add(12, 'down'); } catch (OutOfRangeException $e) { echo $e->getMessage(), PHP_EOL; } foreach ($dll as $key => $val) { echo $key . '=>' . $val, PHP_EOL; } echo "count(): " . $dll->count(), PHP_EOL; echo "top(): " . $dll->top(), PHP_EOL; echo "bottom(): " . $dll->bottom(), PHP_EOL;
/** * Counts the number of tokens in the list. * * @return int Returns the number of tokens in the list. * @link http://www.php.net/manual/en/spldoublylinkedlist.count.php */ public function count() { return $this->tokens->count(); }