PHP code example of ddruganov / php-typed-array

1. Go to this page and download the library: Download ddruganov/php-typed-array library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ddruganov / php-typed-array example snippets


final class SomeClass
{
    public TypedArray $typedArray;

    public function __construct()
    {
        $this->typedArray = TypedArray::of(TypeDescription::of(TypeDescription::INT));
    }
}

final class SomeClass
{
    public TypedArray $typedArray;

    public function __construct()
    {
        $this->typedArray = TypedArray::of(TypeDescription::of(TypeDescription::INT));
    }

    public function someMethod()
    {
        $this->typedArray = TypedArray::of(TypeDescription::of(TypeDescription::STRING));
    }
}

final class DummyArray extends TypedArray
{
    public function __construct()
    {
        parent::__construct(new TypeDescription(DummyClass::class));
    }

    public function offsetGet(mixed $offset): DummyClass
    {
        return parent::offsetGet($offset);
    }
}

$firstArray = new IntArray();
$firstArray[0] = 1;
$firstArray[1] = 2;

$secondArray = new IntArray();
$secondArray[0] = 3;
$secondArray[1] = 4;

$thirdArray = new IntArray();
$thirdArray[0] = 5;
$thirdArray[1] = 6;

$merged = IntArray::from($firstArray, $secondArray, $thirdArray);