當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SplFixedArray::offsetSet方法代碼示例

本文整理匯總了PHP中SplFixedArray::offsetSet方法的典型用法代碼示例。如果您正苦於以下問題:PHP SplFixedArray::offsetSet方法的具體用法?PHP SplFixedArray::offsetSet怎麽用?PHP SplFixedArray::offsetSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SplFixedArray的用法示例。


在下文中一共展示了SplFixedArray::offsetSet方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setup

 public function setup()
 {
     $array = new \SplFixedArray(3);
     $array->offsetSet(0, new StringLiteral('one'));
     $array->offsetSet(1, new StringLiteral('two'));
     $array->offsetSet(2, new Integer(3));
     $this->collection = new Collection($array);
 }
開發者ID:embarknow,項目名稱:value-objects,代碼行數:8,代碼來源:CollectionTest.php

示例2: offsetSet

 /**
  * {@inheritdoc}
  */
 public function offsetSet($index, $newval)
 {
     if (!empty($newval) && false === $newval instanceof Hypothesis) {
         throw new \InvalidArgumentException(sprintf('HypothesesList could only contain Hypothesis, %s given.', get_class($newval)));
     }
     parent::offsetSet($index, $newval);
 }
開發者ID:zloesabo,項目名稱:speechkit-php,代碼行數:10,代碼來源:HypothesesList.php

示例3: offsetSet

 public function offsetSet($offset, $value)
 {
     if (!$this->isValid($offset, $value)) {
         throw new \RuntimeException();
     }
     return parent::offsetSet($offset, $value);
 }
開發者ID:luijar,項目名稱:fp-php,代碼行數:7,代碼來源:Tuple.php

示例4: values

 /**
  * Returns a Collection of the values.
  *
  * @return Collection
  */
 public function values()
 {
     $count = $this->count()->toNative();
     $valuesArray = new \SplFixedArray($count);
     foreach ($this->items as $key => $item) {
         $valuesArray->offsetSet($key, $item->getValue());
     }
     return new Collection($valuesArray);
 }
開發者ID:embarknow,項目名稱:value-objects,代碼行數:14,代碼來源:Dictionary.php

示例5: offsetSet

 /**
  * Set collection item.
  *
  * Warning! `$newval` must not be typehinted to be compatible with `ArrayAccess::offsetSet` method.
  *
  * @param int   $index
  * @param Token $newval
  */
 public function offsetSet($index, $newval)
 {
     $this->changed = true;
     $this->registerFoundToken($newval);
     parent::offsetSet($index, $newval);
 }
開發者ID:jimlind,項目名稱:PHP-CS-Fixer,代碼行數:14,代碼來源:Tokens.php

示例6: SplFixedArray

<?php

/*
  spl 提供一種固定數組數據結構,可以用以替代php的(數字索引)數組
  它的性能更高。
*/
$a = new SplFixedArray(6);
$a[5] = 'iam5';
$a[1] = 'iam7';
//$a['a'] ="aaa";
//對固定數組對象的操作最好使用它提供的方法,而非直接以數組的方式操作,如下是設置數組元素值的方法
$a->offsetSet(0, 'iam0');
// current() 等方法都是操作的數組內部的指針,而非索引
// 默認情況下指針指向數組第一個元素。
$va = $a->current();
var_dump($va);
//將一個普通數組轉換為splfixarray
// 默認保留數字索引,且以最大數字索引為依據生成固定數組大小,如這裏是9+1 = 10
$ar = ['aaa', 'bbb', 6 => 'ccc', 9 => 'ddd'];
$wo = SplFixedArray::fromArray($ar);
$h4 = $wo->offsetExists(6);
var_dump($h4, $wo);
開發者ID:xzungshao,項目名稱:iphp,代碼行數:22,代碼來源:fixArray.php

示例7: offsetSet

 /**
  * @param int $offset
  * @param mixed $value
  */
 public function offsetSet($offset, $value)
 {
     $this->set->offsetSet($offset, $value);
 }
開發者ID:nmarley,項目名稱:bitcoin-php,代碼行數:8,代碼來源:MutableCollection.php

示例8: __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();
 }
開發者ID:Michael-Mosher,項目名稱:Segment,代碼行數:16,代碼來源:model_h.php

示例9: SplFixedArray

<?php

$array = new SplFixedArray(5);
$a = $array->offsetSet(2);
if (is_null($a)) {
    echo 'PASS';
}
開發者ID:badlamer,項目名稱:hhvm,代碼行數:7,代碼來源:SplFixedArray_offsetSet_one_invalid_parameter.php

示例10: offsetSet

 public function offsetSet($n, $v)
 {
     echo "A::offsetSet\n";
     return parent::offsetSet($n, $v);
 }
開發者ID:gleamingthecube,項目名稱:php,代碼行數:5,代碼來源:ext_spl_tests_fixedarray_002.php

示例11:

// 獲得當前節點
$array->current();
// next()
// 指針移動到下一個節點
$array->next();
// setSize(int $size)
// 重新設置陣列數組的大小
$array->setSize(10);
// getSize()
// 獲得陣列數組的大小
$array->getSize();
// offsetExists(int $index)
// 判斷該索引是否存在值,返回boolean
$array->offsetExists(3);
// offsetGet(int $index)
// 獲得該索引對應的值
$array->offsetGet(3);
// offsetSet(int $index, mixed $value)
// 設置該索引對應的值
$array->offsetSet(6, 'value3');
// offsetUnset(int $index)
// 刪除該索引對應的值
$array->offsetUnset(6);
// toArray()
// 將陣列轉化成php數組
// output: Array ( [0] => [1] => 2 [2] => [3] => value2 [4] => [5] => [6] => [7] => [8] => [9] => )
$php_array = $array->toArray();
// fromArray($php_array)
// 將php數組轉化成陣列
// output: SplFixedArray Object ( [0] => [1] => 2 [2] => [3] => value2 [4] => [5] => [6] => [7] => [8] => [9] => )
$spl_array = SplFixedArray::fromArray($php_array);
開發者ID:ray0916,項目名稱:learn,代碼行數:31,代碼來源:splFixedArray.php

示例12: _read

 /**
  * Reads the redis pending response
  * @return string|integer|boolean|array
  * @throws ClientIOError
  * @throws ClientRedisError
  */
 protected function _read()
 {
     $reply = fgets($this->_socket, 512);
     if ($reply === false) {
         $this->onClientIOError('Network error - unable to read header response');
     }
     $reply = trim($reply);
     if (empty($reply)) {
         return null;
     }
     switch ($reply[0]) {
         case '+':
             // inline reply
             $reply = substr($reply, 1);
             return strcasecmp($reply, 'OK') === 0 ? true : $reply;
             break;
         case '-':
             // error
             $this->onClientRedisError(trim(substr($reply, 4)));
             return false;
             break;
         case ':':
             // inline numeric
             return intval(substr($reply, 1));
             break;
         case '$':
             // bulk reply
             $size = intval(substr($reply, 1));
             if ($size === -1) {
                 return null;
             }
             $reply = '';
             if ($size > 0) {
                 $read = 0;
                 do {
                     $block_size = $size - $read > 1024 ? 1024 : $size - $read;
                     $r = fread($this->getSocket(), $block_size);
                     if ($r === FALSE) {
                         $this->onClientIOError('Failed to read bulk response from stream');
                     } else {
                         $read += strlen($r);
                         $reply .= $r;
                     }
                 } while ($read < $size);
             }
             fread($this->getSocket(), 2);
             /* discard crlf */
             return $reply;
             break;
         case '*':
             // multi-bulk reply
             $size = intval(substr($reply, 1));
             if ($size === -1) {
                 return null;
             }
             if ($size === 0) {
                 return array();
             }
             $reply = new \SplFixedArray($size);
             for ($i = 0; $i < $size; $i++) {
                 $reply->offsetSet($i, $this->_read());
             }
             return $reply;
             break;
     }
     $this->onClientRedisError('Undefined protocol response type : ' . $reply);
 }
開發者ID:sergiula,項目名稱:php-worker-manager,代碼行數:73,代碼來源:RedisClient.php

示例13: resize

 protected function resize($size, $count = null)
 {
     $data = new \SplFixedArray($size);
     $count = null === $count ? $this->count : $count;
     $start = (int) (($size - $count) / 2);
     $n = 0;
     $N = $count < $this->count ? $count : $this->count;
     while ($n < $N) {
         $data->offsetSet($n + $start, $this->data->offsetGet($this->map($n)));
         ++$n;
     }
     $this->data = $data;
     $this->start = $start;
     $this->count = $count;
 }
開發者ID:daniel-ac-martin,項目名稱:php-seids,代碼行數:15,代碼來源:ArrayDeque.php

示例14: SplFixedArray

<?php

$array = new SplFixedArray(5);
$a = $array->offsetSet();
if (is_null($a)) {
    echo 'PASS';
}
開發者ID:badlamer,項目名稱:hhvm,代碼行數:7,代碼來源:SplFixedArray_offsetSet_invalid_parameter.php


注:本文中的SplFixedArray::offsetSet方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。