本文整理汇总了PHP中SplObjectStorage::key方法的典型用法代码示例。如果您正苦于以下问题:PHP SplObjectStorage::key方法的具体用法?PHP SplObjectStorage::key怎么用?PHP SplObjectStorage::key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplObjectStorage
的用法示例。
在下文中一共展示了SplObjectStorage::key方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: key
public function key()
{
$this->initialize();
return parent::key();
}
示例2: key
function key()
{
echo __METHOD__ . "(" . parent::key() . ")\n";
return parent::key();
}
示例3: key
/**
* @inheritdoc
*/
public function key()
{
return $this->connections->key();
}
示例4: key
/**
* Return the key of the current element
*
* @link http://php.net/manual/en/iterator.key.php
* @return mixed scalar on success, or null on failure.
* @since 5.0.0
*/
public function key()
{
return $this->collection->key();
}
示例5: insert
private function insert($breadcrumb, $position)
{
if ($position < 0) {
$position += $this->breadcrumbs->count();
} else {
// $position >= 1
$position--;
}
$breadcrumbs = new \SplObjectStorage();
$breadcrumbs->addAll($this->breadcrumbs);
$this->breadcrumbs->removeAll($this->breadcrumbs);
$breadcrumbs->rewind();
while ($breadcrumbs->valid()) {
if (max(0, $position) == $breadcrumbs->key()) {
$this->breadcrumbs->attach($breadcrumb);
}
$this->breadcrumbs->attach($breadcrumbs->current());
$breadcrumbs->next();
}
}
示例6: SplObjectStorage
<?php
// Test code from: http://www.php.net/manual/en/splobjectstorage.getinfo.php
$s = new SplObjectStorage();
$o1 = new StdClass();
$o2 = new StdClass();
$s->attach($o1, "d1");
$s->attach($o2, "d2");
$s->rewind();
while ($s->valid()) {
$index = $s->key();
$object = $s->current();
// similar to current($s)
$data = $s->getInfo();
var_dump($object);
var_dump($data);
$s->next();
}
// now mutate $o2 and ensure it sticks
$s->attach($o2, "mutated");
var_dump($s[$o2]);
示例7: SplObjectStorage
[expect php]
[file]
<?php
// As a map from objects to data
$s = new SplObjectStorage();
$o1 = new StdClass();
$o2 = new StdClass();
$o3 = new StdClass();
$s[$o1] = "data for object 1";
$s[$o2] = "two";
$s[$o3] = 3;
var_dump($s->key(), $s->valid());
示例8: selectObjectByKey
/**
* Move the internal pointer to an object identified by its position in the storage
* @param int $key
* @return bool false if the object doesn't exist
*/
public function selectObjectByKey($key)
{
if (isset($this->map[$key])) {
parent::rewind();
while (parent::valid()) {
if (parent::key() === $key) {
return true;
}
parent::next();
}
}
return false;
}
示例9:
// 将参数对象从对象容器中分离
$obj->detach($o);
// $obj[$o] 报错,找不到对象
// contains(object $object)
// 判断对象容器是否存在该对象
$obj->contains($o);
// false
// count()
// 获得映射对象中的对象数量
$obj->count();
// valid()
// 判断对象容器当前指针后面是否有值
$obj->valid();
// key()
// 返回对象容器当前节点的索引
$obj->key();
// rewind()
// 返回并指向第一个节点元素
$obj->rewind();
// setInfo(mixed $data)
// 给当前节点赋值。必须是调用rewind后,才可以用setInfo赋值,否则找不到对象。
$obj->setInfo('AAA');
// getInfo()
// 获得当前节点的值。也必须是调用rewind后,才可以调用getInfo。
$obj->getInfo();
// current()
// 获得当前节点对象
$obj->current();
// getHash()
// 获得参数的hash值
$obj->getHash($a2);