Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PHP Map
Search
Aimeos
September 04, 2020
Programming
170
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PHP Map
Easy to use and elegant handling for PHP arrays using Map objects
Aimeos
September 04, 2020
More Decks by Aimeos
See All by Aimeos
GraphQL vs. JSON:API
aimeos
1
260
Responsive E-Mails
aimeos
0
710
gigacommerce
aimeos
0
3.2k
High performance e-commerce in Laravel
aimeos
0
950
E-Commerce in TYPO3 mit Aimeos (Deutsch)
aimeos
0
480
Aimeos - high performance e-commerce in TYPO3
aimeos
0
330
Aimeos e-commerce components
aimeos
1
220
E-Commerce in TYPO3 - Reloaded
aimeos
0
340
Micro services as architectural concept
aimeos
0
710
Other Decks in Programming
See All in Programming
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
290
Railsバージョンを4倍にした話
optim
0
900
Event is what happens
moro
2
2.7k
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
320
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
120
8年前のNode.jsを動かして分かった、npm installの裏側
keisukeikeda
0
120
ActionController meets Protocol Buffers
sorah
1
770
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
300
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
1.8k
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.3k
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
140
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
670
Featured
See All Featured
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
A Modern Web Designer's Workflow
chriscoyier
699
190k
How to Ace a Technical Interview
jacobian
280
24k
The Curious Case for Waylosing
cassininazir
1
600
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
440
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.3k
Paper Plane
katiecoart
PRO
5
54k
We Are The Robots
honzajavorek
0
420
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
60k
From π to Pie charts
rasagy
1
430
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