Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHP Map
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Aimeos
September 04, 2020
Programming
1
150
PHP Map
Easy to use and elegant handling for PHP arrays using Map objects
Aimeos
September 04, 2020
Tweet
Share
More Decks by Aimeos
See All by Aimeos
GraphQL vs. JSON:API
aimeos
1
240
Responsive E-Mails
aimeos
0
670
gigacommerce
aimeos
0
3.2k
High performance e-commerce in Laravel
aimeos
0
930
E-Commerce in TYPO3 mit Aimeos (Deutsch)
aimeos
0
460
Aimeos - high performance e-commerce in TYPO3
aimeos
0
320
Aimeos e-commerce components
aimeos
1
210
E-Commerce in TYPO3 - Reloaded
aimeos
0
310
Micro services as architectural concept
aimeos
0
700
Other Decks in Programming
See All in Programming
組織で育むオブザーバビリティ
ryota_hnk
0
170
AgentCoreとHuman in the Loop
har1101
5
220
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
110
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
510
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
AtCoder Conference 2025
shindannin
0
1k
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
590
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
0
910
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
2026年 エンジニアリング自己学習法
yumechi
0
130
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
110
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
The agentic SEO stack - context over prompts
schlessera
0
630
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Rails Girls Zürich Keynote
gr2m
96
14k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
250
Into the Great Unknown - MozCon
thekraken
40
2.2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Amusing Abliteration
ianozsvald
0
96
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
280
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
64
Transcript
PHP Array > Map
Aimeos E-Commerce framework
Why?
$list = [ ['id' => '1', 'value' => 'value1'], ['id'
=> '2', 'value' => 'value2'], null ]; Starting point
$list[] = ['id' => '3', 'value' => 'value3']; unset($list[0]); $list
= array_filter($list); sort($list); $pairs = array_column($list, 'value', 'id'); $value = reset($pairs) ?: null; Current way
Solutions
Laravel collections CakePHP collections Arrayy Underscore.php
(ceased) Others
php-map.org
$value = map( $list ) ->push(['id' => '3', 'value' =>
'value3']) ->remove(0) ->filter() ->sort() ->col('value', 'id') ->first(); Using Map
$map[] = ['id' => '3', 'value' => 'value3']; $value =
$map[0]; count($map); foreach($map as $key => value) {} Still possible
More than array
map() new Map() Map::from() Creating maps
map([1, 2, 3]) map(new Map()) map($iterator) map('abc')
Almost all array methods supported Array methods
concat() collapse() duplicates() flat() countBy()
groupBy() Additional methods except() only() pull() take() skip() ...
each() every() nth() pipe() some()
... Accepting closures
$map->each( function( $val, $key ) { echo $key . ':
' . $val; } ); Closure example
concat() every() find() flat() includes()
join() keys() Like Javascript map() pop() push() reduce() reverse() some() ...
Useful methods map([1,2,3])->join(','); // '1,2,3' Map::split('1,2,3'); // map([1,2,3]) map(['a'=>1,'b'=>2])->toUrl(); //
'a=1&b=2' map(['a'=>1,'b'=>2])->toJson(); // '{"a":1,"b":2}'
Fluent interface $map->push( 'value' ) ->remove( 0 ) ->filter() ->sort();
$e = new \RuntimeException('not found'); map([])->first($e); Find or fail
Map::method( 'strrev', function($sep) { return strrev(join($sep, $this->list)); } ); Map::from(['c',
'b', 'a'])->strrev(' > '); // returns 'a > b > c' Custom methods
jQuery style
class MyClass { private $code; private $status = 0; public
function __construct( $code ) { $this->code = $code; } public function setStatus( int $s ) { $this->stat = $s; return $this; } public function getCode() { return $this->code; } } Example class
$objects = Map::from( [ 'a' => new MyClass( 'x' ),
'b' => new MyClass( 'y' ) ] ); Example Map
$result = $objects ->setStatus(1) ->getCode() ->toArray(); Operations on objects
// status of all object is 1 // $result contains:
['a' => 'x', 'b' => 'y'] Result
?
Aimeos php-map.org Twitter: @aimeos facebook.com/Aimeos