Laravelで多次元配列を1次元化するflatten()が便利だった.
連想配列の値のみを収集して1次元配列にしてくれる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
$ ./vendor/bin/sail artisan tinker Psy Shell v0.11.1 (PHP 8.1.2 — cli) by Justin Hileman >>> $collection = collect([ 'hoge' => [1, 2, 3], ... 'fuga' => 'aiueo', ... 'foo' => 1, ... 'bar' => null ... ]); => Illuminate\Support\Collection {#3529 all: [ "hoge" => [ 1, 2, 3, ], "fuga" => "aiueo", "foo" => 1, "bar" => null, ], } >>> $collection->flatten(); => Illuminate\Support\Collection {#3525 all: [ 1, 2, 3, "aiueo", 1, null, ], } |