public function bytestring($data) { $a = new \SplFixedArray(strlen($data)); for ($i = 0; $i < strlen($data); $i++) { $a[$i] = str_pad(ord($data[$i]), 3, ' ', STR_PAD_LEFT); } return implode(' ', $a->toArray()); }
/** * @param mix $row * * @return bool * * @throws \Exception * @throws \Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException */ private function addRow(&$row) { $countColumns = count($this->columns); $tempRow = new \SplFixedArray($countColumns); for ($i = 0; $i < $countColumns; $i++) { try { $value = $this->propertyAccessor->getValue($row, $this->columns[$i]); } catch (UnexpectedTypeException $exception) { if (true === $this->getAllowNull()) { $value = $this->getNullReplace(); } else { throw $exception; } } $tempRow[$i] = $this->escape($value, $this->columns[$i]); } switch ($this->getFormat()) { case 'csv': $this->data[] = implode($this->getSeparator(), $tempRow->toArray()); break; case 'json': $this->data[] = array_combine($this->data[0], $tempRow->toArray()); break; case 'pdf': case 'listData': case 'render': $this->data[] = $tempRow->toArray(); break; case 'xls': case 'html': $this->data .= '<tr>'; foreach ($tempRow as $val) { $this->data .= '<td>' . $val . '</td>'; } $this->data .= '</tr>'; break; case 'xml': $this->data .= '<row>'; $index = 0; foreach ($tempRow as $val) { $this->data .= '<column name="' . $this->columns[$index] . '">' . $val . '</column>'; $index++; } $this->data .= '</row>'; break; } return true; }
/** * Returns a native array representation of the Collection * * @return array */ public function toArray() { return $this->items->toArray(); }
/** * Loops through constructor args and buid an ordered array of args using * the option values passed in. We assume the passed in array has been resolved already. * i.e. That the arg name has an entry in the option array. * * @param array $hashOfOptions array of options * @return array array of ordered args */ public function hashToArgsArray($hashOfOptions) { $optionsArray = new \SplFixedArray(count($hashOfOptions)); foreach ($this->constructorArgs as $name => $param) { $optionsArray[$param->getPosition()] = $hashOfOptions[$name]; } return $optionsArray->toArray(); }
public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested) { $a += array(Caster::PREFIX_VIRTUAL . 'storage' => $c->toArray()); return $a; }
/** * @param string $note * @param int $octave * @param number $duration * * @return Sample */ public function note($note, $octave, $duration) { $result = new \SplFixedArray((int) ceil($this->getSampleRate() * $duration * 2)); $octave = min(8, max(1, $octave)); $frequency = Note::get($note) * pow(2, $octave - 4); $attack = $this->generator->getAttack($this->getSampleRate(), $frequency, $this->getVolume()); $dampen = $this->generator->getDampen($this->getSampleRate(), $frequency, $this->getVolume()); $attackLength = (int) ($this->getSampleRate() * $attack); $decayLength = (int) ($this->getSampleRate() * $duration); for ($i = 0; $i < $attackLength; $i++) { $value = $this->getVolume() * ($i / ($this->getSampleRate() * $attack)) * $this->getGenerator()->getWave($this->getSampleRate(), $frequency, $this->getVolume(), $i); $result[$i << 1] = Helper::packChar($value); $result[($i << 1) + 1] = Helper::packChar($value >> 8); } for (; $i < $decayLength; $i++) { $value = $this->getVolume() * pow(1 - ($i - $this->getSampleRate() * $attack) / ($this->getSampleRate() * ($duration - $attack)), $dampen) * $this->getGenerator()->getWave($this->getSampleRate(), $frequency, $this->getVolume(), $i); $result[$i << 1] = Helper::packChar($value); $result[($i << 1) + 1] = Helper::packChar($value >> 8); } return new Sample($result->getSize(), implode('', $result->toArray())); }
/** * @return array */ public function all() { return $this->set->toArray(); }
/** * @return Card[] */ public function getCards() : array { return $this->cards->toArray(); }
/** * @covers Intacct\Functions\Common\ReadRelated::setKeys * @expectedException InvalidArgumentException * @expectedExceptionMessage Keys count cannot exceed 100 */ public function testMaxNumberOfKeys() { $keys = new \SplFixedArray(101); $read = new ReadRelated('unittest'); $read->setKeys($keys->toArray()); }
/** * @return array */ public function getList() { return $this->list->toArray(); }
public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested) { $a += array("~storage" => $c->toArray()); return $a; }
/** * Removes the raw data at the given index * * @param int $index */ protected function _removeRawDataForIndex($index) { $basicArray = $this->rawData->toArray(); $newArray = array_merge(array_slice($basicArray, 0, $index), array_slice($basicArray, $index + 1)); $this->rawData = SplFixedArray::fromArray($newArray); }
/** * @dataProvider valuesDataProvider * @param \SplFixedArray $arr * @param array $expected */ public function testInsertionSort(\SplFixedArray $arr, array $expected) { $selectionStrategy = new InsertionSortStrategy(); $this->assertNotEquals($expected, $arr->toArray()); $this->assertEquals($expected, $selectionStrategy->sort($arr)->toArray()); }
// 获得当前节点 $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);
/** * @covers Intacct\Functions\Common\ReadByName::setNames * @expectedException InvalidArgumentException * @expectedExceptionMessage Names count cannot exceed 100 */ public function testMaxNumberOfNames() { $names = new \SplFixedArray(101); $readByName = new ReadByName('unittest'); $readByName->setNames($names->toArray()); }