PHP code example of andrewcarteruk / typed-arrays

1. Go to this page and download the library: Download andrewcarteruk/typed-arrays 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/ */

    

andrewcarteruk / typed-arrays example snippets


use TypedArray\StringArray;

$stringArray = new StringArray(['Hello, World!', 'foo' => 'bar']);
// Or, $stringArray = new StringArray();

try {
    $stringArray[] = 1;
} catch (\InvalidArgumentException $exception) {
    echo $exception->getMessage() . PHP_EOL;
}

use App\Farm\Chicken;
use TypedArray\InstanceArray;

$chickenArray = new InstanceArray(Chicken::class, [new Chicken('Bob')]);

$chickenArray[] = new Chicken('Tony');
$chickenArray['foo'] = new Chicken('Alice');

try {
    $chickenArray[] = 1;
} catch (\InvalidArgumentException $exception) {
    echo $exception->getMessage() . PHP_EOL;
}