Open3

PHP8 Memo

ta.toshiota.toshio
$numbers1 = [1,2,3];
$numbers2 = [4,5];

// Before
$result = array_merge($numbers1, $numbers2);

// After, Result is [1,2,3,4,5]
$result = [...$numbers1, ...$numbers2];
ta.toshiota.toshio

何でしょうこれ。

<?php

class Order {
    public Product $product;
    public function __construct(Product $product)
    {
        $this->product = $product;
    }
}

class Product {
    public Option $option;
    public function __construct(Option $option)
    {
        $this->option = $option;
    } }

class Option {
    public $type;
    public function __construct(string $type)
    {
        $this->type= $type;
    }
}

$order = new Order(new Product(new Option('pdf')));

$type = [
     'pdf' => 'book',
     'epub' => 'book',
     'license' => 'license',
     'artwork' => 'creative',
     'song' => 'creative',
     'nhysical' => 'physical',
][$order->product->option->type];

echo $type; // book

https://mobile.twitter.com/archtechx/status/1469698507422375937

ta.toshiota.toshio

match

$this>sorts[$field] = match ($this->sorts[$field] ?? null) {
     'asc' => 'desc',
     'desc' => null,
    default => ‘asc',
};